Pls change the names to this and the input section must be multiple inputs like send to thingspeak block
ssid will be changed in the ssid
password will be changed in password
Key will be change in apiKey
Input will be changed in the highlighted region
if there is 2 inputs :
getStr +="&field1=";
getStr += "";
getStr +="&field2=";
getStr += "";
Code :
#include <WiFi.h>
String apiKey = "JUIGAGECAIV1X1R8"; //Change this key to your "Write API key"
const char* ssid ="Redmi";
const char* password ="heydoodeh";
void setup() {
WiFi.begin(ssid, password);
Serial.begin(9600);
Serial1.begin(115200); // Arduino to ESP01 Communication
connectWiFi(); // To connect to Wifi
}
void loop() {
// put your main code here, to run repeatedly:
Serial1.println("AT+CIPMUX=0\r\n"); // To Set MUX = 0
delay(2000); // Wait for 2 sec
// TCP connection
String cmd = "AT+CIPSTART=\"TCP\",\""; // TCP connection with https://thingspeak.com server
cmd += "184.106.153.149"; // IP addr of api.thingspeak.com
cmd += "\",80\r\n\r\n"; // Port No. = 80
Serial1.println(cmd); // Display above Command on PC
Serial.println(cmd); // Send above command to Rx1, Tx1
delay(10000); // Wait for 20 Sec
if(Serial1.find("ERROR")) // If returns error in TCP connection
{
Serial.println("AT+CIPSTART error"); // Display error msg to PC
//return;
}
// prepare GET string
String getStr = "GET /update?api_key=";
getStr += apiKey;
getStr +="&field1=";
getStr += ""; // The Value will come here
getStr += "\r\n\r\n";
Serial.println(getStr); // Display GET String on PC
cmd = "AT+CIPSEND="; // send data length
cmd += String(getStr.length());
cmd+="\r\n";
Serial.println(cmd); // Display Data length on PC
Serial1.println(cmd); // Send Data length command to Tx1, Rx1
delay(10000); // wait for 20sec
if(Serial1.find(">")) // If prompt opens //verify connection with cloud
{
Serial.println("connected to Cloud"); // Display confirmation msg to PC
Serial1.print(getStr); // Send GET String to Rx1, Tx1
}
else
{
Serial1.println("AT+CIPCLOSE\r\n"); // Send Close Connection command to Rx1, Tx1
Serial.println("AT+CIPCLOSE"); // Display Connection closed command on PC
}
delay(10000);
}
boolean connectWiFi() { // Connect to Wifi Function
Serial1.println("AT+CWMODE=1\r\n"); // Setting Mode = 1
delay(100); // wait for 100 mSec
String cmd = "AT+CWJAP=\""; // Connect to WiFi
cmd += ssid; // ssid_name
cmd += "\",\"";
cmd += password; // password
cmd += "\"\r\n";
Serial.println(cmd); // Display Connect Wifi Command on PC
Serial1.println(cmd); // send Connect WiFi command to Rx1, Tx1
delay(10000); // wait for 10 sec
Serial1.println("AT+CWJAP?"); // Verify Connected WiFi
if(Serial1.find("+CWJAP"))
{
Serial.println("OK, Connected to WiFi."); // Display Confirmation msg on PC
return true;
}
else
{
Serial.println("Can not connect to the WiFi."); // Display Error msg on PC
return false;
}
}
Pls change the names to this and the input section must be multiple inputs like send to thingspeak block
ssid will be changed in the ssid password will be changed in password Key will be change in apiKey
Input will be changed in the highlighted region
if there is 2 inputs : getStr +="&field1="; getStr += ""; getStr +="&field2="; getStr += "";
Code :