i am sending the data from RTC through arduino to thingspeak. the data sent is shown in the serial monitor but cant see any graph on thingspeak.

7 views (last 30 days)
#include <SoftwareSerial.h> //Software Serial library
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
SoftwareSerial espSerial(2, 3); //Pin 2 and 3 act as RX and TX. Connect them to TX and RX of ESP8266
#define DEBUG true
String mySSID = "MyWiFi "; // WiFi SSID
String myPWD = "1234"; // WiFi Password
String myAPI = "XXXYYY"; // API Key
String myHOST = "api.thingspeak.com";
String myPORT = "80";
String myFIELD1 = "field1";
String myFIELD2 = "field2";
String myFIELD3 = "field3";
void setup() {
Serial.begin(9600);
espSerial.begin(115200);
espData("AT+RST", 1000, DEBUG); //Reset the ESP8266 module
espData("AT+CWMODE=1", 1000, DEBUG); //Set the ESP mode as station mode
espData("AT+CWJAP=\""+ mySSID +"\",\""+ myPWD +"\"", 1000, DEBUG); //Connect to WiFi network
while (!Serial) ; // wait for serial
delay(200);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
}
void loop()
{
tmElements_t tm;
if (RTC.read(tm)) {
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
String hrData = "GET /update?api_key="+ myAPI +"&"+ myFIELD1 +"="+String(tm.Hour);
espData("AT+CIPMUX=1", 1000, DEBUG); //Allow multiple connections
espData("AT+CIPSTART=0,\"TCP\",\""+ myHOST +"\","+ myPORT, 1000, DEBUG);
espData("AT+CIPSEND=0," +String(hrData.length()+4),1000,DEBUG);
espSerial.find(">");
espSerial.println(hrData);
Serial.print("HOUR: ");
print2digits(tm.Hour);
espData("AT+CIPCLOSE=0",1000,DEBUG);
String minuData = "GET /update?api_key="+ myAPI +"&"+ myFIELD2 +"="+String(tm.Minute);
espData("AT+CIPMUX=1", 1000, DEBUG); //Allow multiple connections
espData("AT+CIPSTART=0,\"TCP\",\""+ myHOST +"\","+ myPORT, 1000, DEBUG);
espData("AT+CIPSEND=0," +String(minuData.length()+4),1000,DEBUG);
espSerial.find(">");
espSerial.println(minuData);
Serial.print("MINUTE: ");
print2digits(tm.Minute);
espData("AT+CIPCLOSE=0",1000,DEBUG);
String secData = "GET /update?api_key="+ myAPI +"&"+ myFIELD3 +"="+String(tm.Second);
espData("AT+CIPMUX=1", 1000, DEBUG); //Allow multiple connections
espData("AT+CIPSTART=0,\"TCP\",\""+ myHOST +"\","+ myPORT, 1000, DEBUG);
espData("AT+CIPSEND=0," +String(secData.length()+4),1000,DEBUG);
espSerial.find(">");
espSerial.println(secData);
Serial.print("SECOND: ");
print2digits(tm.Second);
espData("AT+CIPCLOSE=0",1000,DEBUG);
delay(2000);
}
String espData(String command, const int timeout, boolean debug)
{
Serial.print("AT Command ==> ");
Serial.print(command);
Serial.println(" ");
String response = "";
espSerial.println(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (espSerial.available())
{
char c = espSerial.read();
response += c;
}
}
if (debug)
{
//Serial.print(response);
}
return response;
}
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}
  1 Comment
Christopher Stapels
Christopher Stapels on 25 Oct 2019
If your channel is public, can you share the channel number and we can look at the data? If not you can export the data and see what is being sent to ThingSpeak. It may be interpreted as a string intead of a number, and that is why its not showing up on the plot.

Sign in to comment.

Answers (1)

Hans Scharler
Hans Scharler on 25 Oct 2019
I would start by combining all of the update requests into one request.
String secData = "GET /update?api_key="+ myAPI +"&"+ myFIELD2 +"="+String(tm.Second)+"&"+ myFIELD3 +"="+String(tm.Second);

Communities

More Answers in the  ThingSpeak Community

Categories

Find more on Read Data from Channel in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!