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.
1 Answer 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
-
1Thank 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– Duckbenok2017年10月14日 06:42:01 +00:00Commented Oct 14, 2017 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– Duckbenok2017年10月14日 11:04:21 +00:00Commented Oct 14, 2017 at 11:04
WiFi.begin
even successful?