Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:32 28 Nov 2024 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 : Unable to write data to Thingspeak

Author Message
shoots

Newbie

Joined: 31/07/2011
Location: Australia
Posts: 32
Posted: 09:21am 14 Aug 2023
Copy link to clipboard 
Print this post

Hi, I have tried to write to Thingspeak using a WebMite. I have applied various combinations of IP address for the thingspeak site and ports and always receive  "Failed to connect" error message.

I have marked out passwords.
I have been able send data to thingspeak via a url on a web page using   https://api.thingspeak.com/update?api_key=I01xxxxxxxxxN7&field1=29
This works so I know the thingspeak side of things is OK. I have used my username and tried channel number in the MQTT fields to no avail.
Any suggestions welcome please.
Thank you,
Peter


OPTION EXPLICIT
OPTION DEFAULT NONE
option autorun 1
print MM.ver
dim string channelID$="2xxxx"
dim string apiKey$="Ixxxxxxxxxxx7"
print channelID
print apiKey
'to load via terminal when first running:
'option TCP SERVER PORT 80
'OPTION TELNET CONSOLE ON

'WEB NTP 8     'to get time later
'print TIME$
print MM.INFO(IP ADDRESS)
WEB TCP INTERRUPT WebInterrupt
dim integer CurrentTemp=TEMPR(GP15)'16
dim integer CurrentHumid=80
do
print "test"
pause 10000
loop

sub WebInterrupt  'called when a request is made over the web
CurrentTemp=TEMPR(GP15)   'this is a DB18S20
print "in subroutine"

local integer a,p,t,b(512)
FOR a=1 To MM.INFO(MAX CONNECTIONS)'Loop through all the incoming connections
                        '(there could be a number of simultaneous connections)
print a,"   number of connections"
WEB TCP read a,b()    'Read the incoming message into the long string buffer
print b(a)
p=LINSTR(b(),"GET")   'Get the locations of key words in the message
t=LINSTR(b(),"HTTP")  'Get the locations of key words in the message
'r = LINSTR(array%(), search$ [,start]) Returns the position of a string in a long string
IF (p>0) And (t>p) then
WEB TRANSMIT PAGE a%,"index.html"
print TIME$
print "data ",a," a   ",p," p       ",t," t   MMmax",MM.INFO(MAX CONNECTIONS)
PRINT "Temperature: " TEMPR(GP15)
sendThing

endif
next a
end sub

sub sendThing
WEB MQTT CONNECT "192.168.1.137",1883,"Sxxxx","Sxxxxxx"
WEB MQTT PUBLISH,"&field1","35"
'not working-possible wrong approach  WEB OPEN TCP CLIENT https://api.thingspeak.com/update?api_key=I0xxxxxxxxxxxxxIN7&field1=39
'192.168.1.108  'Tried these IP
'184.106.153.149
end sub
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9127
Posted: 09:33am 14 Aug 2023
Copy link to clipboard 
Print this post

WebMite can't support SSL over TLS which may be what Thingspeak needs. Not enough resource. Unless they have a non-secure port there is no solution
 
shoots

Newbie

Joined: 31/07/2011
Location: Australia
Posts: 32
Posted: 09:44am 14 Aug 2023
Copy link to clipboard 
Print this post

Thank you matherp. Saves me sweating over it. I will give MicroPython a try- a pity as I have been enjoying the MMbasic environment for the last few years.
Thank you for your work on it.
Cheers,
Peter
 
davematt
Regular Member

Joined: 27/09/2011
Location: Australia
Posts: 51
Posted: 02:00am 15 Aug 2023
Copy link to clipboard 
Print this post

@shoots, dont give up quite yet. In my ignorance I have been using a webmite to send to Thingspeak very reliably for some weeks. Got a hint from another member. Will forward his PM to you. And post code here if anyone else interested…
Cheers, D
 
Bizzie
Senior Member

Joined: 06/07/2014
Location: Australia
Posts: 191
Posted: 03:48am 15 Aug 2023
Copy link to clipboard 
Print this post

I am sure not only me would like to see the code.
Rob White
 
davematt
Regular Member

Joined: 27/09/2011
Location: Australia
Posts: 51
Posted: 08:31am 15 Aug 2023
Copy link to clipboard 
Print this post

Hi Rob, your wish is my command...
To my knowledge, this has worked perfectly for 12 weeks, all credit to Peter of course, my cattle and I are extremely grateful.

' Thingspeak Test 1.1
'WebMite MMBasic Version 5.07.07
'OPTION SYSTEM SPI GP10,GP11,GP12
'OPTION AUTORUN ON
'OPTION CPUSPEED (KHz) 250000
'OPTION LCDPANEL ILI9488W, RLANDSCAPE,GP8,GP15,GP9,GP13
'OPTION WIFI ********
'OPTION TOUCH GP16,GP17
'GUI CALIBRATE 0, 231, 3963, 1267, -837
'OPTION SDCARD GP22
 
option explicit
option default none
option autorun on

Dim m$,s$, n$, api_key$="XXXXXXXXXXXXXXXX"  ' put your thingspeak key here
DIM buff%(4096/8)
m$="GET http://api.thingspeak.com/update?api_key="+api_key$+"&field1="

Do
Getmessage                             ' waits for message from lo ra

 Batt = val(Arg$(3))
 Level = val(Arg$(4))
 Current = val(Arg$(5))
 Status = Arg$(6)

if timer > 1200000 then                           '20 mins
 s$=m$+Str$(Batt,0,1)+"&field2="+Str$(Current,0,1)+"&field3="
 s$ = s$ + Str$(Level,0,0) + chr$(13) + Chr$(10)
 Web Open TCP Client "184.106.153.149",80  'fixed address for Thingspeak HTTP
 WEB TCP CLIENT REQUEST s$, buff%(4096/8)
 Pause 1000
 buff%(4096/8) = 0
 WEB close TCP Client

end if

Loop
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 10:48am 15 Aug 2023
Copy link to clipboard 
Print this post

Davematt--thanks for posting your working code. Sometimes the key is not knowing that something "won't work".

Note that you can preserve the formatting of your code when posting (which I suspect you had by the single space indent following the "if") by enclosing it within the tags "[ CODE]" and "[ \CODE]" (upper case but without spaces) or by pasting it in after clicking the "code" button above the posting window.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 11:47am 15 Aug 2023
Copy link to clipboard 
Print this post

Or attach as a file.

John
 
shoots

Newbie

Joined: 31/07/2011
Location: Australia
Posts: 32
Posted: 01:55pm 15 Aug 2023
Copy link to clipboard 
Print this post

Hi Davematt, thank you for the encouragement and the program. I will have a go with it. I can see there's more than one way to achieve an outcome when it comes to programming. I spent some time grappling with MicroPython and ended up having a win but it was a tedious process! All good learning though. The little Pico W is a pretty cool item.
Cheers,
Peter
 
Print this page


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

© JAQ Software 2024