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 0
|
| 2 |
+
String str;
|
| 3 |
+
String finaldata ;
|
| 4 |
+
int sound ;
|
| 5 |
+
float hum;
|
| 6 |
+
float temp;
|
| 7 |
+
int x;
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
////////////////////////////////////////////////////////////cry
|
| 11 |
+
int t = 0;
|
| 12 |
+
////////////////////////////////////////////////////////534 cry
|
| 13 |
+
|
| 14 |
+
////////////////////////////////////////////////////////dfplayer
|
| 15 |
+
#include "SoftwareSerial.h"
|
| 16 |
+
#include "DFRobotDFPlayerMini.h"
|
| 17 |
+
|
| 18 |
+
// Use pins 2 and 3 to communicate with DFPlayer Mini
|
| 19 |
+
static const uint8_t PIN_MP3_TX = 2; // Connects to module's RX
|
| 20 |
+
static const uint8_t PIN_MP3_RX = 3; // Connects to module's TX
|
| 21 |
+
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX);
|
| 22 |
+
|
| 23 |
+
// Create the Player object
|
| 24 |
+
DFRobotDFPlayerMini player;
|
| 25 |
+
|
| 26 |
+
////////////////////////////////////////////////////////dfplayer
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
////////////////////////////////////////////////////////////light
|
| 30 |
+
const int analogInPin = A0;
|
| 31 |
+
////////////////////////////////////////////////////////////light
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
////////////////////////////////////////////////sdx////////////humidity
|
| 36 |
+
#include <dht11.h>
|
| 37 |
+
#define DHT11PIN 4
|
| 38 |
+
dht11 DHT11;
|
| 39 |
+
////////////////////////////////////////////////////////////humidity
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
////////////////////////////////////////////////////////wet
|
| 43 |
+
#define sensor_DO 7
|
| 44 |
+
////////////////////////////////////////////////////////wet
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
void setup() {
|
| 49 |
+
// Init USB serial port for debugging
|
| 50 |
+
Serial.begin(9600);
|
| 51 |
+
pinMode(8, OUTPUT);
|
| 52 |
+
pinMode(9, OUTPUT);
|
| 53 |
+
// Init serial port for DFPlayer Mini
|
| 54 |
+
softwareSerial.begin(9600);
|
| 55 |
+
|
| 56 |
+
// Start communication with DFPlayer Mini
|
| 57 |
+
if (player.begin(softwareSerial)) {
|
| 58 |
+
//Serial.print("OK");
|
| 59 |
+
player.volume(20);
|
| 60 |
+
} else {
|
| 61 |
+
//Serial.print("Connecting to DFPlayer Mini failed!");
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
void loop() {
|
| 66 |
+
//Serial.print("755_");
|
| 67 |
+
////////////////////////////////////////////////////////wet
|
| 68 |
+
int rain = digitalRead(sensor_DO);
|
| 69 |
+
////////////////////////////////////////////////////////wet
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
////////////////////////////////////////////////////////////humidity
|
| 74 |
+
int chk = DHT11.read(DHT11PIN);
|
| 75 |
+
////////////////////////////////////////////////////////////humidity
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
////////////////////////////////////////////////////////////cry
|
| 80 |
+
int sensorValue = analogRead(A1);
|
| 81 |
+
int n = sensorValue;
|
| 82 |
+
|
| 83 |
+
sensorValue = analogRead(A1);
|
| 84 |
+
//Serial.println("noise :");
|
| 85 |
+
//Serial.print(sensorValue);
|
| 86 |
+
if (abs(n - sensorValue) >= 10) {
|
| 87 |
+
t += 1;
|
| 88 |
+
}
|
| 89 |
+
//Serial.print("t :");
|
| 90 |
+
//Serial.print(t);
|
| 91 |
+
//Serial.print("_");
|
| 92 |
+
if (t==3) {
|
| 93 |
+
player.play(1);
|
| 94 |
+
}
|
| 95 |
+
if (t >= 3) {
|
| 96 |
+
digitalWrite(8, HIGH);
|
| 97 |
+
digitalWrite(9, LOW);
|
| 98 |
+
sound=1;} //on
|
| 99 |
+
//Serial.print(sound);
|
| 100 |
+
else {
|
| 101 |
+
sound=0; //off
|
| 102 |
+
//Serial.print(sound);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
////////////////////////////////////////////////////////////cry
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
////////////////////////////////////////////////////////////humidity
|
| 111 |
+
//Serial.print("Humidity (%): ");
|
| 112 |
+
hum=((float)DHT11.humidity);
|
| 113 |
+
//Serial.print(hum);
|
| 114 |
+
//Serial.print("_");
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
//Serial.print("Temperature (C): ");
|
| 118 |
+
temp=((float)DHT11.temperature);
|
| 119 |
+
//Serial.print(temp);
|
| 120 |
+
//Serial.print("_");
|
| 121 |
+
////////////////////////////////////////////////////////////humidity
|
| 122 |
+
|
| 123 |
+
////////////////////////////////////////////////////////wet
|
| 124 |
+
//if (val == 1) {
|
| 125 |
+
//Serial.print("Dry_");
|
| 126 |
+
//rain=("Dry_");
|
| 127 |
+
//} else {
|
| 128 |
+
//Serial.print("Wet_");
|
| 129 |
+
//rain=("Wet_");
|
| 130 |
+
//}
|
| 131 |
+
////////////////////////////////////////////////////////wet
|
| 132 |
+
|
| 133 |
+
////////////////////////////////////////////////////////////light
|
| 134 |
+
//Serial.print("light : ");
|
| 135 |
+
x=(analogRead(analogInPin));
|
| 136 |
+
|
| 137 |
+
////////////////////////////////////////////////////////////light
|
| 138 |
+
|
| 139 |
+
//finaldata = "755_" + String(t) + "_" + sound + String(hum) + "_" + String(temp) + "_" + String(rain) + String(analogRead(analogInPin));
|
| 140 |
+
//Serial.println(t + "," + sound + "," + hum + "," + temp + "," + rain + "," + x);
|
| 141 |
+
|
| 142 |
+
Serial.print(t);
|
| 143 |
+
Serial.print(",");
|
| 144 |
+
Serial.print(sound);
|
| 145 |
+
Serial.print(",");
|
| 146 |
+
Serial.print(hum);
|
| 147 |
+
Serial.print(",");
|
| 148 |
+
Serial.print(temp);
|
| 149 |
+
Serial.print(",");
|
| 150 |
+
Serial.print(rain);
|
| 151 |
+
Serial.print(",");
|
| 152 |
+
Serial.println(x);
|
| 153 |
+
|
| 154 |
+
delay(1000);
|
| 155 |
+
}
|
esp.ino
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <ESP8266WiFi.h>
|
| 2 |
+
#include <WiFiClientSecure.h>
|
| 3 |
+
#include <ESP8266HTTPClient.h>
|
| 4 |
+
|
| 5 |
+
const char* ssid = "Violet<3";
|
| 6 |
+
const char* password = "01491625";
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
String API_URL = "https://jqwumpunrezhqtdruqbs.supabase.co";
|
| 10 |
+
String API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Impxd3VtcHVucmV6aHF0ZHJ1cWJzIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTM5NTY5MTEsImV4cCI6MjAyOTUzMjkxMX0.0U4LdChmGtXxWnCODTWzQ8JgAgffkRcPhJ78x9s9rao";
|
| 11 |
+
String TableName = "sensors";
|
| 12 |
+
const int httpsPort = 443;
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
int sendingInterval = 1200;
|
| 17 |
+
|
| 18 |
+
HTTPClient https;
|
| 19 |
+
WiFiClientSecure client;
|
| 20 |
+
|
| 21 |
+
void setup() {
|
| 22 |
+
Serial.begin(9600);
|
| 23 |
+
delay(10);
|
| 24 |
+
|
| 25 |
+
Serial.println();
|
| 26 |
+
Serial.println("Connecting to ");
|
| 27 |
+
Serial.println(ssid);
|
| 28 |
+
|
| 29 |
+
WiFi.begin(ssid, password);
|
| 30 |
+
|
| 31 |
+
while (WiFi.status() != WL_CONNECTED) {
|
| 32 |
+
delay(500);
|
| 33 |
+
Serial.print(".");
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
Serial.println("");
|
| 37 |
+
Serial.println("WiFi connected");
|
| 38 |
+
Serial.println("IP address: ");
|
| 39 |
+
Serial.println(WiFi.localIP());
|
| 40 |
+
|
| 41 |
+
client.setInsecure();
|
| 42 |
+
}
|
| 43 |
+
void loop() {
|
| 44 |
+
if (WiFi.status() == WL_CONNECTED) {
|
| 45 |
+
if (Serial.available() > 0) {
|
| 46 |
+
String data = Serial.readStringUntil('\n');
|
| 47 |
+
float t,sound,hum,temp,rain,x;
|
| 48 |
+
|
| 49 |
+
sscanf(data.c_str(), "%f,%f,%f,%f,%f,%f", &t,&sound,&hum,&temp,&rain,&x);
|
| 50 |
+
https.begin(client, API_URL + "/rest/v1/" + TableName);
|
| 51 |
+
https.addHeader("Content-Type", "application/json");
|
| 52 |
+
https.addHeader("Prefer", "return=representation");
|
| 53 |
+
https.addHeader("apikey", API_KEY);
|
| 54 |
+
https.addHeader("Authorization", "Bearer " + API_KEY);
|
| 55 |
+
|
| 56 |
+
int httpCode = https.POST("{\"t\":" + String(t) + ",\"sound\":" + String(sound) + ",\"hum\":" + String(hum)+ ",\"temp\":" + String(temp)+ ",\"rain\":" + String(rain)+ ",\"x\":" + String(x) + "}");
|
| 57 |
+
String payload = https.getString();
|
| 58 |
+
Serial.println(httpCode);
|
| 59 |
+
Serial.println(payload);
|
| 60 |
+
|
| 61 |
+
https.end();
|
| 62 |
+
}
|
| 63 |
+
} else {
|
| 64 |
+
Serial.println("Error in WiFi connection");
|
| 65 |
+
}
|
| 66 |
+
delay(1000);
|
| 67 |
+
}
|