some commands to use Thingspeak. I already had the DHT11 Temperature and Humidity sensor connected (and there is a LDR on the test board). Some time ago i created a freeThingspeak account and tried to use it with my home automation system. So it was only a little step to try the ESP8266 Basic Thingspeak API. This is in the "ESP8266Basic Language reference":
FUNCTIONS (THINGSPEAK API) To get started with thing speak visit there web site at https://thingspeak.com/ You need to have an account and channel/api key all set up. These functions will only work if the esp is connected to a network with the internet. SENDTS: Will post the fields contents to the thingspeak service. Must use the thingspeak key and field number. SENDTS({KEY},{FIELD NUMBER},{FIELD CONTENTS}) READTS: Will return the last value published for the desired field. Must use the thingspeak key, channel id and field number. Bla = readts({KEY},{CHANNEL ID},{FIELD NUMBER}) |
I want to record the DHT11 Temperature, Humidity and Analog input ( LDR )
First i tested one Channel and only one field to figure out the type of data (numeric or string) that was needed. When this was oke i created 2 more fields on this channel
Field 1: temp
Field 2: hum
Field 3: ana
and tried to write the data to this channel. In the program below key1$=key2$=key3$ = the secret key of channelA (and tested also some modifications of this program).
In Thingspreak i missed some data!
I tried writing data in a different order to the fields i also missed data.
The best order to write data seemed 3 , 2 , 1 not 1 , 2 , 3
However the last field always missed data.
I played with delays and also with delays between writing to the Fields.
I created more channels did write date to different channels
( key1$= secret key of channelA, key2$= secret key of channelB, key3$= secret key of channelC)
Then all data did arrive!
I expect there is some little bug in the ESP8266Basic code or some strange thing.
tkey1$ = "MySecretKey000000001"
tkey2$ = "MySecretKey000000002"
tkey2$ = "MySecretKey000000003"
DHT.SETUP( 11 , PinDHT11 )
html "<h1>Logging data and storing to Thingspeak</h1>"
TIMER 6000 , [GETDAT]
html "<h2>Start Store and log</h2>"
wait
[GETDAT]
t = DHT.TEMP()
h = DHT.HUM()
a = io(ai)
p$ = time() & ", Temp = " & t & ", Hum = " & h & ", Analog(ldr) = " & a
html p$
MyDatT = str( t )
MyDatH = str( h )
MyDatA = str( a )
SENDTS( tkey3$ , "3" , MyDatA )
html " ( Send 3 MyDatA: " & MyDatA & ") "
SENDTS( tkey2$ , "2" , MyDatH )
html " ( Send 2 MyDatH: " & MyDatH & ") "
SENDTS( tkey1$ , "1" , MyDatT )
html " ( Send 1 MyDatT: " & MyDatT & ") "
html "<br>"
wait
[EXIT]
end
No comments:
Post a Comment