7:45 pm

July 10, 2018

Need help in reading and writing voltage values on my thingspeak channel. I keep getting "'esp8266' was not declared in this scope" error. It would be appreciated if someone can help me by tonight.
here is the code that I used:
const float referenceVolts = 3.3;
const int batteryPin = 0;
#include "Arduino.h"
#include "ThingSpeak.h"
#define DEBUG true //show messages between ESP8266 and Arduino in serial port, when set to true
#define SSID "CACT"
#define PASS "VOSTRO022a"
String sendAT(String command, const int timeout, boolean debug)
{
String response = "";
esp8266.print(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266.available())
{
char c = esp8266.read();
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}
void setup() {
Serial.begin(9600); // initialize serial communication at 9600 bits per second
esp8266.begin(9600); ////begin the software serial communication with a baud rate of 9600
analogWriteResolution(10);
sendAT("AT+RST
", 2000, DEBUG); // call sendAT function to send reset AT command
sendAT("AT
", 1000, DEBUG);
sendAT("AT+CWMODE=1
", 1000, DEBUG); //call sendAT function to set ESP8266 to station mode
sendAT("AT+CWJAP=\""SSID"\",\""PASS"\"
", 2000, DEBUG); //AT command to connect with the Wi-Fi network
while(!esp8266.find("OK")) { //wait for connection
}
sendAT("AT+CIFSR
", 1000, DEBUG); //AT command to print IP address on serial monitor
sendAT("AT+CIPMUX=0
", 1000, DEBUG); //AT command to set ESP8266 to multiple connections
}
// the loop routine runs repeatedly forever:
void loop() {
// read the input on analog pin 0:
int val = analogRead(batteryPin);
analogWrite(DAC0, 300);
analogWrite(DAC1, 800);
// print out the value you read:
float volts = (val / 1023.0) * referenceVolts;
Serial.println(volts);
delay(100); // delay in between reads for stability
}
void updateTS(String T,String P){
Serial.println("");
sendAT("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80
", 1000, DEBUG);
delay(2000);
String cmdlen;
String cmd="GET /update?key=KX9IF911J8PEBEMU&field1="+T+"&field2="+P+"
"; // update the voltage values on thingspeak URL
cmdlen = cmd.length();
sendAT("AT+CIPSEND="+cmdlen+"
", 2000, DEBUG);
esp8266.print(cmd);
Serial.println("");
sendAT("AT+CIPCLOSE
", 2000, DEBUG);
Serial.println("");
delay(15000);
}
Most Users Ever Online: 166
Currently Online:
49 Guest(s)
Currently Browsing this Page:
2 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
Advantagetreeexperts, laundrydaddyuk, techhhelp5, ken, tran, huldacormierModerators: cstapels: 460
Administrators: Hans: 405, lee: 457