0

I have tried using the thingspeak-arduino library and tested some of the examples:

#include <WiFi.h>
#include <WiFiClient.h>
#include <SPI.h>
#include <ThingSpeak.h>
char ssid[] = "Benok4G";    //  your network SSID (name)
char pass[] = "password";   // your network password
WiFiClient  client;

unsigned long myChannelNumber = 344468;
const char * myReadAPIKey = "xxxxxxxxx";


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  WiFi.begin(ssid, pass);
  ThingSpeak.begin(client);    
}

void loop() {
  // put your main code here, to run repeatedly:
  float voltage = ThingSpeak.readFloatField(myChannelNumber, 1, myReadAPIKey);

  Serial.print("Latest voltage is: ");
  Serial.print(voltage);
  Serial.println("V");

  delay(30000);
}

When i run this code, I get this on the Serial Monitor. enter image description here

Why is it 0.00? It's supposed to be 24.0

http://184.106.153.149/channels/344468/fields/1/last

Did I do something wrong? I am very frustrated because I've tried a lot of methods already just to fetch the data from ThingSpeak to my Arduino using ESP8266. I can send but when receiving I am really lost and confused.

  • Are you sure that those libraries support ESP8266 over AT commands? Is WiFi.begin even successful? – gre_gor Oct 13 '17 at 18:54
  • I have a similar problem. Arduino Mega + Exp8266 connected to Serial1 (RX1, TX1). With WiFiEsp.h library, it connects to the router but no reading on thingspeak, always timeout 605. I wonder if you can post the working program. Thanks and good job. – FixEsp Feb 3 '18 at 16:57
1
#include <WiFi.h>

From the WiFi library reference page:

With the Arduino WiFi Shield, this library allows an Arduino board to connect to the internet.

From the Arduino WiFi Shield product page:

It is based on the HDG204 Wireless LAN 802.11b/g System in-Package. An AT32UC3 provides a network (IP) stack capable of both TCP and UDP.

But you're not using an Arduino WiFi Shield or anything compatible. You're using an ESP8266 which is completely different. Thus you can't use the WiFi library for your project.

Instead you will need to use the appropriate ESP8266 library. If you are programming the ESP8266 directly that will be the ESP8266WiFi library, which is bundled with the ESP8266 core for Arduino. If you are using the ESP8266 as a WiFi module controlled via AT commands that will be the WiFiEsp library

  • 1
    Thank you for your response. I have solved my problem. I included the WiFiEsp library and set the SoftwareSerial Serial1(6, 7); // RX, TX and set the baud rate at 9600. Works like charm. Thank you again. – Duckbenok Oct 14 '17 at 6:42
  • Just a follow up. It worked but sometimes I get "Timed Out" response and Sending the data takes too long than doing AT commands. Is this normal? – Duckbenok Oct 14 '17 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.