Introduction: SIS

Picture of SIS

Wifi uploading multiple sensor data:

Step 1:

/*

1. Upload this code and open the serial monitor 2. On the serial monitor enter the command AT 3. If the response is OK, your esp8266 serial baud rate is 115200. Close this sketch and run the example code. Then on the void setup make this change: espSerial.begin(115200); and upload the code. If you want to change the speed to 9600 use the command AT+UART_CUR=9600,8,1,0,0

4. Otherwise if you can't see anything on the serial display reset the ESP8266 module change the esp8266 serial baud rate to 9600 or other, until you get a response. Then enter the command AT+UART_CUR=115200,8,1,0,0 to change the speed to 115200 *

/ AT Command to display the OK message // AT+GMR Command to display esp8266 version info // AT+UART_CUR=9600,8,1,0,0 Command to change the ESP8266 serial baud rate to 9600 // AT Command to change the ESP8266 serial baud rate to 115200 AT+UART_CUR=115200,8,1,0,0

// Hardware serial test - Arduino MEGA #include //Attention: For new DHT11 version library you will need the Adafruit_Sensor library //Download from here: https://github.com/adafruit/Adafruit_Sensor

//Attention: For new DHT11 version libraries you will need the Adafruit_Sensor library //Download from here:https://github.com/adafruit/Adafruit_Sensor //and install to Arduino software

#define DHTPIN 5 // Connect the signal pin of DHT11 sensor to digital pin 5 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE);

String apiKey = "EXUATURT9PJNWY3S"; // replace with your channel's thingspeak WRITE API key

String ssid="SSID"; // Wifi network SSID

String password ="XXXXXXX"; // Wifi network password

boolean DEBUG=true;

boolean thingSpeakWrite(float value1, float value2, int value3){

String cmd = "AT+CIPSTART=\"TCP\",\""; // TCP connection

cmd += "184.106.153.149"; // api.thingspeak.com

cmd += "\",80"; Serial1.println(cmd);

if (DEBUG) Serial.println(cmd);

showResponse(5000);

if(Serial1.find("Error")){

if (DEBUG) Serial.println("AT+CIPSTART error");

return false;

}

String getStr = "GET /update?api_key="; // prepare GET

string getStr += apiKey;

getStr +="&field1=";

getStr += String(value1);

getStr +="&field2=";

getStr += String(value2);

getStr +="&field5=";

getStr += String(value3);

// ...

getStr += "\r\n\r\n";

// send data length

cmd = "AT+CIPSEND=";

cmd += String(getStr.length());

Serial1.println(cmd);

if (DEBUG) Serial.println(cmd);

delay(100);

if(Serial1.find(">")){

Serial1.print(getStr);

if (DEBUG) Serial.print(getStr);

} else{

Serial1.println("AT+CIPCLOSE"); // alert user

if (DEBUG) Serial.println("AT+CIPCLOSE");

return false;

}

return true;

}

void showResponse(int waitTime){

long t=millis();

char c;

while (t+waitTime>millis()){

if (Serial1.available()){

c=Serial1.read();

if (DEBUG) Serial.print(c);

}

}

}

void setup() {

Serial.begin(9600);

Serial1.begin(115200); // or 115200

dht.begin(); // Start DHT

sensor pinMode(8, OUTPUT);

//espSerial.println("AT+RST"); // Enable this line to reset the module;

//showResponse(1000);

//espSerial.println("AT+UART_CUR=9600,8,1,0,0"); // Enable this line to set esp8266 serial speed to 9600 bps //showResponse(1000);

Serial1.println("AT+CWMODE=1"); // set esp8266 as client

showResponse(1000);

Serial1.println("AT+CWJAP=\""+ssid+"\",\""+password+"\""); // set your home router SSID and password showResponse(5000);

if (DEBUG) Serial.println("Setup completed"); }

void loop() {

float t = dht.readTemperature();

float h = dht.readHumidity();

int l = analogRead(A0); // read the value from the LDR

Serial.println("Light = "+String(l));

if (l < 100){

digitalWrite(8, HIGH);

} else {

digitalWrite(8, LOW);

}

if (isnan(t) || isnan(h)) {

if (DEBUG) Serial.println("Failed to read from DHT");

}

else {

if (DEBUG) Serial.println("Temp="+String(t)+" *C");

if (DEBUG) Serial.println("Humidity="+String(h)+" %");

thingSpeakWrite(t,h,l); // Write values to thingspeak

} // thingspeak needs 15 sec delay between updates,

delay(20000);

}

Step 2:

Comments

Lectric Wizard (author)2017-03-02

Needs an intro- What's an SIS? What does it do?

Swansong (author)2017-03-02

Thanks for sharing :)