writing a string to a field

bill buersch on 23 Apr 2021
Latest activity Reply by bill buersch on 23 Apr 2021

I find this is possible to do, but how does one read the data back.

Christopher Stapels
Christopher Stapels on 23 Apr 2021

There are several ways to read the data back, detailed on this page about reading data . The three ways are with the REST API, MATLAB, and MQTT API.

bill buersch
bill buersch on 23 Apr 2021

ok, I'll have to learn REST API. I mostly use stuff like CodeRead = ThingSpeak.readLongField(myChannelNumber, RequestField, myReadAPIKey); with Arduino.

This is a real cool product by the way!

Christopher Stapels
Christopher Stapels on 23 Apr 2021 (Edited on 23 Apr 2021)

Thanks, I like it a lot too! The ThingSpeak Arduino library uses the REST API behind the scenes, as do reads from MATLAB. Are you trying to read data from desktop MATLAB or from MATLAB in ThingSpeak or from a device? I really recommend the getting started tutorial in the doc. It goes over a lot of ThingSpeak functionality.

bill buersch
bill buersch on 23 Apr 2021

So I've been using rest api all along just didn't know it had that particular name. Jargon has its own Moore's law. lol

bill buersch
bill buersch on 23 Apr 2021

I have a bunch of esp8266 controlling lights and related, and each device sends a number to thingspeak when it turns something on or off, then I can look at the numbers in the graph and see what is going on, I also have devices read the numbers and perform actions based on what is requested. So, a request field and and an action field. Then I thought why not use a field to write strings to for certain abnormal things going on. I found I could do that, but they never show in the typical graphs of the field, but I found them when downloading the channel. So I guess my question is, if I write a string, how do I get to see what is there in the graphs you get when you look at any other field of the channel.

Christopher Stapels
Christopher Stapels on 23 Apr 2021

Thanks for clarifying your question. I can think of at least two ways to show strings. One is to use the status field. In your channel settings view, check "Show Status" and the last value posted to the status field will show on your channel view. To write status, add &status= to your rest call, or use the ThingSpeak.setstatus call in the Arduino library. The second method is a custom MATLAB visualization that will interpret and display the strings. You can use the text or annotate methods to put words on a figure. The standard field plots will only show numbers.

bill buersch
bill buersch on 23 Apr 2021
 "Show Status" was already checked. Is there another field besides the 8?  I notice that under add visualizations there is a status field.  Mine shows nothing. So I guess to date nothing has been recorded there.  I will look up the ThingSpeak.setstatus in the cpp file.  Thanks!
bill buersch
bill buersch on 23 Apr 2021

So, is show status another place to put a message about say, some field you just updated? Interesting. I'll have to play around with that. Also, it has something about a twitter tweet, will this also send message to that? I have never used twitter, but that might fun to play with.

/* Function: setStatus Summary: Set the status field of a multi-field update. Parameters: status - String to write (UTF8). ThingSpeak limits this to 255 bytes. Returns: Code of 200 if successful. Code of -101 if string is too long (> 255 bytes) Notes: To record a status message on a write, call setStatus() then call writeFields(). Use status to provide additonal details when writing a channel update. Additonally, status can be used by the ThingTweet App to send a message to Twitter. */ int setStatus(String status) { #ifdef PRINT_DEBUG_MESSAGES Serial.print("ts::setStatus(status: "); Serial.print(status); Serial.println("\")"); #endif // Max # bytes for ThingSpeak field is 255 (UTF-8) if(status.length() > FIELDLENGTH_MAX) return ERR_OUT_OF_RANGE; this->nextWriteStatus = status; return OK_SUCCESS; };

Tags

No tags entered yet.