#include //needed for LCD control // initialize the library by associating any needed LCD interface pin // with the arduino pin number it is connected to const int rs = 12, en = 11, d4 = 7, d5 = 6, d6 = 5, d7 = 4; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); String AP = "D_LINK_259701"; // SSID name, enter your own network name String PASS = "Abracadabra@2"; // and enter your network Password String REG_KEY = "witjmvmox0x9"; // hardware registration key on takano (do not confuse with user registration key!) String HOST = "iotsprint.com"; //website Arduino should send http request to String PORT = "80"; //default port int countTrueCommand; int countTimeCommand; boolean found = false; int tempPin = 1; int timeout = 0; int first, last, first1, last1; String stringTwo, stringThree, data, data1, data2, content; void negotiate_modem() //sequence of AT commands from Arduino to ESP8266 { //this function allows the Arduino to connect to the router sendCommand("AT+CWMODE=1", 50, "OK"); sendCommand("AT+CIPMUX=1", 50, "OK"); sendCommand("AT+CWJAP=\"" + AP + "\",\"" + PASS + "\"", 150, "OK"); } void setup() { Serial.begin(115200); lcd.begin(16, 2); // Print a message to the LCD. lcd.print(" takano example"); delay(2000); sendCommand("AT", 50, "OK"); lcd.clear(); } void loop() { //read the LM35 temperature sensor analog input on analogue pin1 data = ""; data1 = ""; data2 = ""; content = ""; if (found == false) negotiate_modem(); //if Arduino did not get a proper string back from cloud, then try to connect to modem again. Maybe power was recyled to modem for example.. float celsius = (500.0 * analogRead(tempPin)) / 1024.0; //5V or 5000mV correspond to 1024 steps of 10-bit AD converter, and LM35 increases by 10mV per degree C.. stringTwo = String(celsius); stringThree= String(stringTwo); if (stringTwo.length() == 5) stringThree = stringTwo.substring(0, stringTwo.length() - 1); //trim it to 4 characters if (stringThree.length() < 2) stringThree = "000" + stringThree; //to make sure it has 4 characters length else if (stringThree.length() < 3) stringThree = "00" + stringThree; //to make sure it has 4 characters length else if (stringThree.length() < 4) stringThree = "0" + stringThree; //to make sure it has 4 characters length stringThree = "T=" + stringThree; // stringThree = “T=23.4” for example lcd.setCursor(0, 0); lcd.print(stringThree); String getData = "GET /tk.php?r="+REG_KEY+"&m=" + stringThree + " HTTP/1.0"; sendCommand("AT+CIPSTART=4,\"TCP\",\"iotsprint.com\",80", 10, "OK"); sendCommand("AT+CIPSEND=4,71", 10, ">"); Serial.println(getData); delay(2000); countTrueCommand++; //46 read_cloud("Host:iotsprint.com:80"); //25 delay(3000); } void read_cloud(String command) { data = ""; data1 = ""; Serial.println(command); Serial.println(); timeout = 0; while (Serial.available() == 0) { if ( ++timeout > 10000) { // set this to your timeout value in milliseconds break; } } timeout = 0; // got a char so reset timeout content = Serial.readString(); // read the incoming data as string if (content.indexOf("L=") >= 0) //slider value is 0 to 100 { first = content.indexOf("L=") + 2; last = content.lastIndexOf("S="); data = content.substring(first, last - 1); } if (content.indexOf("S=") >= 0) //switch value is either 0 (off) or 1 (on) { first1 = content.indexOf("S=") + 2; last1 = first1 + 1; data1 = content.substring(first1, last1); } if ((data != "") && (data1 != "")) { data2 = "S="+data1+" "+"L=" +data+" "; lcd.setCursor(0, 1); lcd.print(data2); } } void sendCommand(String command, int maxTime, char readReplay[]) { found = false; while (countTimeCommand < (maxTime * 1)) { Serial.println(command); if (Serial.find(readReplay)) //ok { found = true; break; } countTimeCommand++; } if (found == true) { countTrueCommand++; countTimeCommand = 0; } if (found == false) { countTrueCommand = 0; countTimeCommand = 0; } }