mathworks / thingspeak-arduino

ThingSpeak Communication Library for Arduino, ESP8266 and ESP32
https://thingspeak.com
438 stars 231 forks source link

NaN Problems with more than one Field in one Channel #65

Closed quiddi-github closed 4 years ago

quiddi-github commented 4 years ago

Hi there, first thanks for the Library. It is stable and works. Nice work.

Today I found an issue. With your library, it is only possible to send one value to one field to Thingspeak. As an example, you send Data to Thingspeak with ThingSpeak.writeField(myChannelNumber, 2, h, myWriteAPIKey); This sends the value "h" to the Field Number 2 of my Channel on Thingspeak. If I now want to send a value to Field Number 1 in the same Channel I need to execute ThingSpeak.writeField(myChannelNumber, 1, h, myWriteAPIKey); For sending two values to different Fields but existing on the same Channel Number in Thingspeak, I need to execute in the loop: ThingSpeak.writeField(myChannelNumber, 1, h, myWriteAPIKey); delay(20000); ThingSpeak.writeField(myChannelNumber, 2, h, myWriteAPIKey); The problem is that if you send data to Field 1 to Thingspeak, Thingspeak automatically writes an empty entry to Field 2. From this follows that Thingspeak writes a "NaN"-Entry (Not a Number) to Field 2.

And this is the reason why the data on Thingspeak with two Fields in one channel looks like this: Here is an example of my data if I use two fields: 63.4000 NaN 62.1000 NaN 65.0000 NaN 68.0000 NaN 70.9000 NaN 73.0000 NaN 75.2000 NaN 75.4000 NaN 75.3000 NaN

For example, if you use three Fields it looks like this: 63.4000 NaN NaN 65.0000 NaN NaN 70.9000 NaN NaN 75.2000 NaN NaN 75.3000 NaN

Thanks.

v-c commented 4 years ago

writeField updates the channel right away. If you execute 2 or more writeField requests within 15s (as a free license user), the second will be rejected because you are only allowed to update a channel once every 15s. I suggest taking a look at this example as the way to update multiple fields in a channel:

https://github.com/mathworks/thingspeak-arduino/tree/master/examples/ESP32/WriteMultipleFields