mathworks / thingspeak-arduino Goto Github PK
View Code? Open in Web Editor NEWThingSpeak Communication Library for Arduino, ESP8266 and ESP32
Home Page: https://thingspeak.com
ThingSpeak Communication Library for Arduino, ESP8266 and ESP32
Home Page: https://thingspeak.com
Read back a field gives an error and doesn't work anymore!
Hello,
I am trying to compile the sketch on Arduino 101, but I get an error:
`Arduino: 1.6.10 (Mac OS X), Board: "Arduino/Genuino 101"
WARNING: library ThingSpeak claims to run on [avr architecture(s) and may be incompatible with your current board which runs on esp8266 architecture(s).
In file included from /Users/x/Documents/Arduino/Display_temp_LCD_RHT03_connectWiFi_uploadTS/Display_temp_LCD_RHT03_connectWiFi_uploadTS.ino:57:0:
/Users/x/Documents/Arduino/libraries/ThingSpeak/src/ThingSpeak.h:61:4: error: #error Only Arduino MKR1000, Yun, Uno/Mega/Due with either WiFi101 or Ethernet shield. ESP8266 also supported.
#error Only Arduino MKR1000, Yun, Uno/Mega/Due with either WiFi101 or Ethernet shield. ESP8266 also supported.
^
/Users/x/Documents/Arduino/libraries/ThingSpeak/src/ThingSpeak.h:84:3: error: #error "Platform not supported"
#error "Platform not supported"
^
exit status 1
Error compiling for board Arduino/Genuino 101.
`
I cannot understand why the board is listed as not esp8266 -> not compatible, while ESP8266 is afterwards declared as "also suported"
ChannelNumber
is used for debug printing but not used for sending values.
How about to remove it from functions about sending?
I think that only using WRITE_API_KEY
is enough.
Thank you.
Is there any hope of making it work with ESP8266 modem with AT commands ?
Is there any compatible WiFi library ?
The library does not URL encode the strings in setField() or setStatus(). String with special characters, such as %, do not update the channel. Strings will need to be URL encoded prior to calling setField() of setStatus().
I'm using the ESP8266 and I've noticed that data uploads are missed if interrupts or timers(ticker) are used. Is there functionality that checks whether data is uploaded successfully?
This API is not included yet. It would be useful.
Matlab has posted code - but it is only for mkr1000 or esp - but not for ethernet shield:
You can use the bulk-update API in certain scenarios when you want to conserve your device power. When using the bulk-update API, you can collect data over a period of time and then upload the data to ThingSpeak™. Bulk-update API takes JSON encoded data and updates the channel.
Hi,
I noticed that you own bridge.io as a domain name although your domain name is thinkspeak.com. I'm interested in purchasing that domain name from you. Please feel free to contact me at [email protected].
Thanks,
Andrew
It seem the main part of src/ThingSpeak.cpp is missing
Hello,
i'm using your library with my DIY-Weatherstation.
The outside station sends every ten minutes temperature, humidity and pressure to ThingSpeak and after that it goes to deepsleep.
The inside station messures the inside temperature and the humidity and fetch the outside data from ThingSpeak to show it on an 2.4" TFT-screen. Both stations use a Wemos D1 Mini Pro (feat. ESP8266)
If i'm using the ThingSpeak library it takes about five seconds to get the temperature, humidity and pressure as float from TS. That's not good, because in this five seconds my display and the rest of the ESP8266 is doing nothing. I'm receiving the time from an NTP server and print it also on the display, and so the time stands still for five seconds and then proceed.
What i tested so far: I tried the example-sketch provided by the library and set the delay to one second (instead of 15 in the example). It took also about five seconds for the data to be shown on the serial monitor. So i think my code ist OK.
Is there a way to get the data faster?
My code of getting the data is:
float TS_Temp = ThingSpeak.readFloatField( ChannelID, 1, APIREADKEY);
I hope you can help me and now what i mean. Sorry for my bad English. I'm from Germany and my English is a little bit rusty.
Regards
Johnny
I´m trying to use thingspeak with a NODEMCU from Lolin, and every time i try to compile the program i receive the error 'client' was not declared in this scope
pointing to the ThingSpeak.begin(client);
inside the setup() session.
Hi,
I tried the read private channel example with my ardino uno and esp8266, but i had trouble with the WiFi.h library and the WiFIClient type. i don't realy know if i should include the library (if i won't include it' there is no such type wificluient, which is needed for the thingspeak functions...)
I know it's not a major thing, but there are a few mistakes in the read me file.
for example:
Complete documentation in aslo shown below.
should be
Complete documentation is also shown below.
I've noticed ThingSpeak.writeField() function takes around 7-10 seconds for publishing data to channel, while if we use simple HTTPClient, it takes only 1-2 seconds on same network and same channel.
please for any one with idea on how to upload sensor data to thingspeak cloud using arduino uno and gsm shield help me I'm a new in this field of cloud computing though i know to program with arduino
i am trying to read the channel's latitude/longitude in arduino.
There is no method in the library to do so.
If i try to use readraw to do this
ThingSpeak.readRaw(myChannelNumber, ".json", myReadAPIKey);
the request fails with responsecode 400
It support ethernet shield but not module. There is a custom library for this module and thingspeak but it is very very bad , it takes minutes about an update with many failures and retryings. This is the custom library https://github.com/jcw/ethercard/blob/master/examples/thingspeak/thingspeak.ino.
I hope to update it as soon as possible ENC28J60 module is used so much!
I was getting a compiler error when trying to include the library via the web IDE. After I forked your repo and commented out the include, I was able to compile. I sorry I can't say what that will do to the other platforms you support. Thanks for the great library.
Hi,
Could the thingspeak backend server accept both forms of parameters? So that it will give a big help to the memory critical environment like the board Arduino uno wifi which has 2KB ram only...
Thanks
The ThingSpeak sever recently changed to use "chunked transfer encoding" for read requests.
So there is no Content-Length inside the htpp header, which is necessary for the current (V1.5.0) implementation of getHTTPResponse in case of be called by readRaw.
So currently the read functions do not work at least in my implementation.
I made a workaround for me, but this is not very nice.
https://community.thingspeak.com/forum/esp8266-wi-fi/suddenly-appearing-problems-reading-data-by-esp/
Is it possible to provide a library that supports the recognition of "chunked transfer encoding" use.
Many thanks for an answer.
error when compile on esp board.
in ThingSpeak.h
#define ERR_TIMEOUT -304 // Timeout waiting for server to respond
and in err.h (Arduino/hardware/espressif/esp32/tools/sdk/include/lwip/lwip)
#define ERR_TIMEOUT -3 /* Timeout. */
when change ERR_TIMEOUT in ThingSpeak.h to other (eg. ERR_TIMEOUT_1) can be compiled.
I have not been able to get things peak commands to work with arduino ide and Wemos D1 mini. Anyone have a solution or change I need make?
For example, the readPrivateChannel example appears to run, but value returned is always 0.00 or null. I do not get any error messages.
thingspeak-arduino/src/ThingSpeak.h
Line 81 in c735e4d
The extra round bracket gives compilation error, removing it solve the error
Hi, I am using Wee Esp8266 Wifi Board. It's library is doesn't declare Client
https://github.com/itead/ITEADLIB_Arduino_WeeESP8266
How can I use this library without Client definition?
Code works. But writevoltages ex only works 1/20 iterations.
it works on my adafruit esp8266.. thanks guys..
code:
/*
WriteVoltage
Reads an analog voltage from pin 0, and writes it to a channel on ThingSpeak every 20 seconds.
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and
analyze live data streams in the cloud.
Copyright 2017, The MathWorks, Inc.
Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed.
See the accompaning licence file for licensing information.
*/
#include "ThingSpeak.h"
// ***********************************************************************************************************
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
// Yun, Ethernet shield, WiFi101 shield, esp8266 and MKR1000 are all supported.
// EPS32 is only partially compatible. ADC analogRead() for ESP32 has not yet been implemented in the SparkFun library. It will always return 0.
// With Yun, the default is that you're using the Ethernet connection.
// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below
// ***********************************************************************************************************
//#define USE_WIFI101_SHIELD
//#define USE_ETHERNET_SHIELD
// #define (ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
char ssid[] = "ssid"; // your network SSID (name) --subject to change to your own network and password
char pass[] = "pwd"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
// On ESP8266: 0 - 1023 maps to 0 - 1 volts
#define VOLTAGE_MAX 1.0
#define VOLTAGE_MAXCOUNTS 1023.0
/*
**** Visit https://www.thingspeak.com to sign up for a free account and create
**** a channel. The video tutorial http://community.thingspeak.com/tutorials/thingspeak-channels/
**** has more information. You need to change this to your channel, and your write API key
**** IF YOU SHARE YOUR CODE WITH OTHERS, MAKE SURE YOU REMOVE YOUR WRITE API KEY!!
*****************************************************************************************/
unsigned long myChannelNumber = 5752; // your thingspeak channel no.
const char * myWriteAPIKey = "AWJZGFEIB4DT1"; //your thingspeak writeapikey.
void setup() {
WiFi.begin(ssid, pass);
ThingSpeak.begin(client);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading
// On Uno,Mega,YunArduino: 0 - 1023 maps to 0 - 5 volts
// On ESP8266: 0 - 1023 maps to 0 - 1 volts
// On ESP32: 0 - 4095 maps to 0 - 1 volts, but will always return 0 as analogRead() has not been implemented yet
// On MKR1000,Due: 0 - 4095 maps to 0 - 3.3 volts
float voltage = sensorValue * (VOLTAGE_MAX / VOLTAGE_MAXCOUNTS);
// Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different
// pieces of information in a channel. Here, we write to field 1.
ThingSpeak.writeField(myChannelNumber, 1, voltage, myWriteAPIKey);
delay(20000); // ThingSpeak will only accept updates every 15 seconds.
}
For a project of mine I need to clear the data of a channel every time a sketch start. Can you implement a method in your library to achieve this results ?
Hi,
I'am trying to send float value to ThingSpeak server. After reading the code, it seems that the float value is converted to char *.
However, it does not seems to be sent correctly to ThingSpeak server( '?' value is sent, which is not correct )
The issue is directly reproductible with your tests
ts::writeField (channelNumber: 31461 writeAPIKey: AFAKEAPIKEYFAKEX field: 1 value: 1.00000)
ts::writeField (channelNumber: 31461 writeAPIKey: AFAKEAPIKEYFAKEX field: 1 value: "?")
ts::writeRaw (channelNumber: 31461 writeAPIKey: AFAKEAPIKEYFAKEX postMessage: "field1=?")
Connect to default ThingSpeak URL...Success.
POST "field1=?&headers=false
I couldn't get the esp32's WriteMultipleFields example to work until I adjusted ThingSpeak.h. Until then it was giving:
Problem updating channel. HTTP error code 302
As a workaround, I added an additional line to my copy of ThingSpeak.h's writeRaw()
// Post data to thingspeak
if(!this->client->print("POST /update HTTP/1.1\r\n")) return abortWriteRaw();
if(!writeHTTPHeader(writeAPIKey)) return abortWriteRaw();
if(!this->client->print("Content-Type: application/x-www-form-urlencoded\r\n")) return abortWriteRaw();
if(!this->client->print("Content-Length: ")) return abortWriteRaw();
if(!this->client->print(postMessage.length())) return abortWriteRaw();
if(!this->client->print("\r\n\r\n")) return abortWriteRaw();
if(!this->client->print(postMessage)) return abortWriteRaw();
if(!this->client->print("\r\n")) return abortWriteRaw(); //possible fix?
I'm too new at this to say whether it's a needed fix or if it's a usage error.
Hi
I do setLatitude and setLongitude.
the initial setting worked
Option in Channel enabled : show location. Google maps with location was displayed.
now I wanted to change the location with new setLongitude, etc.
But nothing is updated.
What am I doing wrong?
Even in channel settings, location (longitude, latitude) are saying 0 but in Graph I do see the former location set on the map.
ThingSpeak.setLongitude(longitude);
ThingSpeak.setElevation(elevation);
ThingSpeak.setLatitude(latitude);
Thanks T
Looking through the library, memory use seems excessive due to the use of static strings stored in SRAM as well as program memory, as well as class variables that are larger than required.
All of this, combined, should radically reduce the memory usage of this library. Remember, this is being used on embedded-scale devices, with very, very limited memory - and often people wish to use other libraries. This sort of wasteful memory use makes things harder for people, and prevents the use of as many libraries as the devices could otherwise support. It would be quite nice if you were to fix this.
Hi
I am working with your libraary and I am very happy. Good job.
sorry for raising this as an issue.
Maybe it is only for information.
DId not understand how to get the response and entry key after Thingspeak.writeFields.
Thanks for an example.
Cheers.
I note that there appears to be many issues associated with sending floats as part of the sendmultiple fields workflow. I have experienced this myself recently working for the Arudino/ESP8266 example however attempting to setFields with float values.
A quick look at line 1647 of ThingSpeak.h suggests that there may be an error in function convertFloatToChar (can someone with better knowledge than I please check this?) as follows:
Line 1647 of ThingSpeak.h reads:
dtostrf(value,1,5,valueString);
however reference to https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__stdlib_1ga060c998e77fb5fc0d3168b3ce8771d42.html and others suggest that the 2nd parameter (currently coded as '1') should be the "minimum field width of the output string including possible negative signs and possible decimal point" with the third value '5' predetermining that the precision (i.e. number of digits after the decimal sign) will be 5. Given the test is for 19+1 (defined in line 350 of the same code) I would have thought the second field should also be 19 (instead of 1).
I'm hoping this gets a whole bunch of people out of trouble moving forward. Given the 'strange behaviour' and the number of reported issues around this, perhaps an example can be included in the documentation (or the existing example modified to show correct casting or alternate methods required).
Would it be possible for you to add support for the new Arduino Uno Wifi board? It supports writing to a ThingSpeak channel with the Ciao library, however, the Ciao library adds so much overhead that my sketch for a temp controller for a beer fermenter (details here) runs out of SRAM at run time.
I'm hoping that this would be a fairly easy addition to the library.
Thanks!
Michael
hii,
i am interfacing esp8266 01 with arduino-uno i don't understand that while thingspeak.write() is called then on what pin i m supposed to connect to TX and RX of the esp to the arduino
please help me .
asap....
send me mail
[email protected]
Hello,
From the example "WriteVoltage", if I add :
#include <WiFi101OTA.h>
….
void setup() {
…..
WiFiOTA.begin("Arduino", "password", InternalStorage);
}
void loop() {
WiFiOTA.poll();
…...
}
I have the error code -301 (Failed to connect to ThingSpeak)
Could you help me to use ThingSpeak with OTA functionality ?
Can someone please add upload confirmation to the writeFields() example? I have a counter that needs to clear when the upload is successful. Something like char error = ThingSpeak.writeFields() ); if (error = 200), count= 0; serial.print(error)
Im not good at reading the .h files to understand what is returned.
Thanks for your help.
Hi there,
using a ESP8266 NodeMCU to post humidity data to TS every 60s.
This works very well.
The only issue I have is that the wifi connection seems to get opened and closed instantly whenever a post to TS is done, so I get a new connection and instant disconnect on the router - which it does not really seem to like much.
This happens when I use the default "WriteMultipleFields.ino" example.
So is there a way to keep the wifi connection open between posts?
Best,
-T
I am having trouble sending multiple values to thingspeak so I tried sample code but its not working either. I enabled PRINT_DEBUG_MESSAGES from ThingSpeak.h file then realized something weird.
If I send 4 field values it is ok but after 4 fields POST becomes empty:
ts::tsBegints::setServer (default)ts::setField (field: 1 value: "1.68622")
ts::setField (field: 2 value: "0.56696")
ts::setField (field: 3 value: "0.75269")
ts::setField (field: 4 value: "0.86510")
ts::writeRaw (channelNumber: 31461 writeAPIKey: LD79EOAAWRVYF04Y postMessage: "field1=1.68622&field2=0.56696&field3=0.75269&field4=0.86510")
Connect to default ThingSpeak URL...Success.
POST "field1=1.68622&field2=0.56696&field3=0.75269&field4=0.86510&headers=false"
Entry ID "8885" (8885)
disconnected.
ts::tsBegints::setServer (default)ts::setField (field: 1 value: "1.68622")
ts::setField (field: 2 value: "0.56696")
ts::setField (field: 3 value: "0.75758")
ts::setField (field: 4 value: "0.86510")
ts::setField (field: 5 value: "1.28543")
ts::writeRaw (channelNumber: 31461 writeAPIKey: LD79EOAAWRVYF04Y postMessage: "field1=1.68622&field2=0.56696&field3=0.75758&field4=0.86510&field5=1.28543")
Connect to default ThingSpeak URL...Success.
POST ""
Entry ID "8883" (8883)
disconnected.
Can the Arduino update the location parameters in my channel?
Hi there, this ESP8266 module connects throught a shield on UNO using serrial 0 and 1 pins.
Thingspeak library does not work with this module... coudl you check and advice?
Thanks
I'm trying to send multiple fields to my channel, but it is failing.
Using
ThingSpeak.setField(1,my1Value); ThingSpeak.setField(2,my2Value); ThingSpeak.writeFields(myChannel,myWriteAPI);
Could you review the code if it matches the latest API, please?
Hello,
I have a simple example that just sets a variety of fields and then writes them in bulk. However, sometimes the writeFields call doesn't seem to complete.
Here is the log:
09:56:26.429 -> ts::setField (field: 2 value: "26.00000")
09:56:26.429 -> ts::setField (field: 3 value: "90.00000")
09:56:26.429 -> ts::setField (field: 4 value: "0.00000")
09:56:26.429 -> ts::setField (field: 5 value: "0.00000")
09:56:36.462 -> ts::setField (field: 6 value: "0.69811")
09:56:36.462 -> ts::setField (field: 7 value: "2.00000")
09:56:36.462 -> ts::setField (field: 8 value: "0.00000")
09:56:36.462 -> Connect to default ThingSpeak: api.thingspeak.com:80...[hostByName] request IP for: api.thingspeak.com
09:56:36.462 -> [hostByName] Host: api.thingspeak.com IP: 34.226.171.107
09:56:36.462 -> :ur 1
09:56:36.462 -> :del
09:56:36.462 -> :ref 1
And that's it. Typically for a successfull call there is a response from writeFields like so:
09:45:44.505 -> Success.
09:45:44.505 -> ts::writeFields (channelNumber: 797035 writeAPIKey: XXXXXXXXXXX)
Any idea what could be happening?
Hello, I have the following issue, whenever I reach initialization of ThinkgSpeak ThingSpeak.begin(wifiObj); I get an error of "Stack Smashing protect Failure!".
Now, I know in which scenario this occurs, but I don't know what causes it and how to solve it.
Whenever I use ThingSpeak in a simple arduino sketch everything is fine, however, when I use xTaskCreatePinnedToCore for multitasking, I get the error. I guess that this has something to do with the stack size declared in the xTaskCreatePinnedToCore, but no matter how much memory I allocate I keep getting this error.
Please help!
Hi!
I'm trying to get this to work with an ESP8266 (on an NodeMCU board).
To most sketches the ESP acts as a arduino with wifi board.
However, if I copy the WriteVoltage example, and force it (remove the other options) to a Wifi board, and include the esp8266 library, this library gives an error:
/Users/PanMan/Documents/Arduino/libraries/ThingSpeak/src/ThingSpeak.h:217:7: note: no known conversion for argument 1 from 'WiFiClient' to 'int&'
no matching function for call to 'ThingSpeakClass::begin(WiFiClient&)'
Hello,
it will be nice to have support for reading last X values from ThingSpeak channel into the array.
Needs documentation on how to choose to use a different Thingspeak Server (for example one you have installed yourself on your own Linux Server).
pinVoltage = 1.0;
ThingSpeak.setField(8,pinVoltage);
ThingSpeak.setCreatedAt("2017-03-17T20:59:59");
value = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
is not working - return code is 200 but no data point appears
The raw function works:
String postMessage = String("field1=20&field2=8&created_at=2017-03-17T20:59:59");
String value;
value = ThingSpeak.writeRaw(myChannelNumber, postMessage, myWriteAPIKey);
The library does not work with SSL connections.
I uploaded the certificate to the Wifi module but got error 301
In the end, I had to go into Thingspeak.h to change the port from 80 to 443
Would be good if there is a option to set the mode between HTTP and HTTPS
Hello, I'm having problems with wifi connection using your example code "WriteMultipleFields". Sometimes ESP module can't connect to wifi and just keep printing dots over serial line. I think the problem is with location of WiFi.begin. In your example code in located inside while loop, but in offical wifi example code it's located outside while loop. As soon as I move to outside of while loop, wifi is connecting correctly.
`
// Connect or reconnect to WiFi
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.