Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:25 10 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Pi-cromite: IOT with ThingSpeak

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 01:44pm 30 Nov 2017
Copy link to clipboard 
Print this post

This example shows how to log data to Thingspeak with the Pi-cromite. It uses the Pi-cromite's TCP client capability. The code measures the temperature every 30 seconds and then uploads the current temperature and the running maximum and minimum to Thingspeak. I was surprised how easy this was


option explicit
option default none
Dim m$,s$, n$, api_key$="my Write API Key"
Dim float current,maxtemp=-1000.0,mintemp=1000.0
m$="GET http://api.thingspeak.com/update?api_key="+api_key$+"&field1="
Do
TCP client "184.106.153.149",80 'fixed address for Thingspeak HTTP
current=DS18B20(33)
If current>maxtemp Then maxtemp=current
If current<mintemp Then mintemp=current
s$=m$+Str$(current)+"&field2="+Str$(maxtemp)+"&field3="+Str$(mintemp)
s$=s$+Chr$(13)+Chr$(10)
Print s$;
TCP send s$
Pause 1000
TCP receive n$ 'clear the TCP receive buffer
TCP close
Pause 29000
Loop


You can see the cold UK temperature here

Edited by matherp 2017-12-02
 
kg4pid
Regular Member

Joined: 08/03/2015
Location: United States
Posts: 50
Posted: 05:41pm 30 Nov 2017
Copy link to clipboard 
Print this post

I'm trying to follow your code but I don't see where you provide a login/user name along with a password. In looking at the web page I see a 'channel id'. Why do I not see this in the code?

While it looks simple, there must more code/setting that are somewhere else.

MaxEdited by kg4pid 2017-12-02
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 08:41pm 30 Nov 2017
Copy link to clipboard 
Print this post

It's probably in the first line below,
api_key$=

Uses an api key instead of username/pwd by the look of it.

  matherp said  

Dim m$,s$, n$, api_key$="my Write API Key"
Dim float current,maxtemp=-1000.0,mintemp=1000.0
m$="GET http://api.thingspeak.com/update?api_key="+api_key$+"&field1="
..
..

Edited by Phil23 2017-12-02
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10565
Posted: 08:29am 01 Dec 2017
Copy link to clipboard 
Print this post

  Quote  While it looks simple, there must more code/setting that are somewhere else.


There isn't otherwise I would have included it.

The Write API Key is the username/password and channel id combined on ThingSpeak which is why I didn't include my key
 
Azure

Guru

Joined: 09/11/2017
Location: Australia
Posts: 446
Posted: 09:57am 01 Dec 2017
Copy link to clipboard 
Print this post

I thought you were going to share
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025