Hey guys, how you doing? Hope that everything goes well!
So I'm trying to upload data to my channel to ThingSpeak (Moisture sensor, Light sensor "TSL2561", and Temperature & Humidity sensor "DHT22") with an arduino uno with ESP8266-01.
Here are my connection for ESP
GND >> GND
RXD >> Pin 3
TXF >> Pin 2
CH_PD & VCC >> 3.3v
And the sensors connection are good! I guss!!
Here is the code I'm using
#include<SoftwareSerial.h>
SoftwareSerial esp8266(2, 3);
bool isDebug = false;
String writeAPIKey = ""; // Here you will write you API Write Code
//-- IoT Information
#define SSID ""; //Here your wirless name
#define PASS "" // Your Password
#define IP "184.106.153.149" // ThingSpeak IP Address: 184.106.153.149
String GET = "GET /update?key="+writeAPIKey;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
esp8266.begin(115200);
connectWiFi();
}
String res;
void loop() {
// put your main code here, to run repeatedly:
//YOUR LOGIC
//-------------------
updateTS(x,y,z);
}
void updateTS( String T, String L , String H)
{
// ESP8266 Client
String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
cmd += IP;
cmd += "\",80";
sendData(cmd,false);
delay(2000);
if ( esp8266.find( "Error" ) )
{
Serial.print( "RECEIVED: Error\nExit1" );
return;
}
//Here you will repeat for each filed in your channel
cmd = GET + "&field1=" + T + "&field2=" + L + "&field3=" + H + "\r\n";
esp8266.print( "AT+CIPSEND=" );
esp8266.println( cmd.length() );
if (esp8266.find( ">" ) )
{
Serial.print(">");
Serial.print(cmd);
esp8266.print(cmd);
}
else
{
sendData( "AT+CIPCLOSE",false);//close TCP connection
}
if ( esp8266.find("OK") )
{
Serial.println( "RECEIVED: OK" );
}
else
{
Serial.println( "RECEIVED: Error\nExit2" );
}
}
String sendData(String cmd, bool isDebug) {
String resp = "";
esp8266.println(cmd);
while (esp8266.available()) {
char c = esp8266.read();
resp += c;
}
if (isDebug) {
Serial.print(resp);
}
return resp;
}
boolean connectWiFi()
{
sendData("AT+CWMODE=1", true); //WiFi STA mode - if '3' it is both client and AP
delay(2000);
//Connect to Router with AT+CWJAP="SSID","Password";
// Check if connected with AT+CWJAP?
String cmd = "AT+CWJAP=\""; // Join accespoint
cmd += SSID;
cmd += "\",\"";
cmd += PASS;
cmd += "\"";
sendData(cmd, true);
delay(5000);
if (esp8266.find("OK"))
{
//esp8266.println("RECEIVED: OK");
Serial.println("Connected");
return true;
}
else
{
// debug.println("RECEIVED: Error");
Serial.println("ERROR HERE");
return false;
}
cmd = "AT+CIPMUX=0";// Set Single connection
sendData(cmd, false);
if ( Serial.find( "Error") )
{
// debug.print( "RECEIVED: Error" );
return false;
}
Serial.println("CONNECTED");
}
So I try to run the sketch and I get that error
Arduino: 1.8.2 (Windows 8.1), Board: "Arduino/Genuino Uno"
C:\Users\Yuu\Documents\Arduino\sketch_may17a\sketch_may17a.ino: In function 'void loop()':
sketch_may17a:30: error: 'x' was not declared in this scope
updateTS(x,y,z);
^
sketch_may17a:30: error: 'y' was not declared in this scope
updateTS(x,y,z);
^
sketch_may17a:30: error: 'z' was not declared in this scope
updateTS(x,y,z);
^
exit status 1
'x' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
So anyone can help?! Thanks in advance