update data to thingspeak

Questions and discussion about The WiPy 1.0 board and CC3200 boards.
Target audience: Users with a WiPy 1.0 or CC3200 board.
jiemde
Posts: 10
Joined: Sun Jun 19, 2016 12:07 pm
Location: Belgium
Contact:

update data to thingspeak

Post by jiemde » Sun Jun 26, 2016 10:22 am

Hello,
Is someone has working with Thingspeak for sending datas ?
I try to use urllib from Lucien2K (https://github.com/lucien2k/wipy-urllib) without success.
Can someone helping ?

Best regards

Jiemde

jiemde
Posts: 10
Joined: Sun Jun 19, 2016 12:07 pm
Location: Belgium
Contact:

Re: update data to thingspeak

Post by jiemde » Sun Jul 03, 2016 6:22 pm

Hello, I'm a little bit dissapointed about the no response about my question.
Wipy seem to be a good candidate for Iot world, but if this board cannot communicate with a server on internet it's not an Iot!
I've ordered an Lopy board and I expect that this one can communicate in Lora ! or in Wifi !
I think that the documentation is very poor and not many examples or tutorial are available.
Is there a way to obtain some help when you facing a problem specially for new user ?

Waiting an answer.

Best regards

Jiemde

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: update data to thingspeak

Post by dhylands » Sun Jul 03, 2016 6:37 pm

You asked about thingspeak. My guess is the fact that nobody answered is because nobody else (on this forum) is using it.

There are many servers on the internet with many different protocols (dozens if not hundreds). I suspect that the WiPy is perfectly capable of talking to thingspeak, but that doesn't mean that it works "out of the box", and since nobody has used it, nobody knows if there are any gotchas or other wrinkles that you might run into.

jiemde
Posts: 10
Joined: Sun Jun 19, 2016 12:07 pm
Location: Belgium
Contact:

Re: update data to thingspeak

Post by jiemde » Sun Jul 03, 2016 6:46 pm

Thanks Dave,

I understand! but is it possible to have some "models", because I've try a lot of libraries for Upython but without success!
Question: can I use "normal" libraries from Python 3 with the Wipy ? or is it necessary to use µpython one ?
Best regards

Jiemde

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: update data to thingspeak

Post by dhylands » Sun Jul 03, 2016 7:22 pm

Some python libraries will run without modiication. Many though, will require modification because they would require many megabytes of memory which the WiPy just doesn't have.

The upython modules are written with "micro" in mind. The regular python libraries are not, and happily assume that there are many megabytes of memory available.

jiemde
Posts: 10
Joined: Sun Jun 19, 2016 12:07 pm
Location: Belgium
Contact:

Re: update data to thingspeak

Post by jiemde » Wed Jul 06, 2016 9:39 am

Hi,
I have a question: what to choose between Urequests library ?
https://github.com/lucien2k/wipy-urllib ... equests.py or
https://github.com/micropython/micropyt ... equests.py ?

Is there some "examples" using these libraries ?

Best regards

Jiemde

mnelsoneorm
Posts: 14
Joined: Wed Jul 20, 2016 4:53 am

Re: update data to thingspeak

Post by mnelsoneorm » Sat Aug 13, 2016 10:37 pm

After a quick look it seems like you could use MQTT? I've been testing the umqtt.simple for displaying messages on a feather huzzah with oled thru mosquitto on a RPi3 and it's working quite well. I can't say for sure on thingspeak because I do see something about mqspeak and it's a little unclear whether you need a broker to act as a bridge to thingspeak or can you send MQTT directly?

quantalume
Posts: 15
Joined: Thu Aug 04, 2016 3:04 pm

Re: update data to thingspeak

Post by quantalume » Thu Aug 25, 2016 9:38 pm

Here is some code I wrote to update a feed on ThingSpeak. I hope it is useful to someone. I apologize that the BBCode formatting tags do not seem to be working.

[code]
from network import WLAN
import socket
import ssl

# Edit these to suit your particular situation
api_key = 'XXXXXXXXXXXXXXX'
field_name = 'field1'
field_value = 75
ssid = 'your-ssid'
auth = (WLAN.WPA2, 'your-key')

wlan = WLAN(mode=WLAN.STA)
wlan.connect(ssid=ssid, auth=auth)
print(wlan.ifconfig())

host = 'api.thingspeak.com'
path = '/update?api_key=' + api_key + '&' + field_name + '=' + str(field_value)

addr = socket.getaddrinfo(host, 443)[0][-1]

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_SEC)
ss = ssl.wrap_socket(s)
ss.connect(addr)

msg = 'GET /' + path + ' HTTP/1.0\r\n\r\n'

ss.send(bytes(msg, 'utf8'))
[/code]

jgmdavies
Posts: 57
Joined: Tue Aug 09, 2016 2:39 pm

Re: update data to thingspeak

Post by jgmdavies » Fri Aug 26, 2016 11:04 am

@quantalume

Many thanks. I've been posting to ThingSpeak using urequests.py and urequest.py, but haven't got these to work with HTTPS.

If I try to do a second 'ss.send' after a delay, I'm getting OSError 1 ("operation not permitted") - any ideas please?

Update: of course it works if I recreate the socket...

Jim

quantalume
Posts: 15
Joined: Thu Aug 04, 2016 3:04 pm

Re: update data to thingspeak

Post by quantalume » Fri Aug 26, 2016 5:26 pm

[quote="jgmdavies"]
If I try to do a second 'ss.send' after a delay, I'm getting OSError 1 ("operation not permitted") - any ideas please?

Update: of course it works if I recreate the socket...[/quote]

I've only been updating my feeds once every 15 minutes, so I close and reopen the socket each time. It would be interesting to know if the WiPy or ThingSpeak are killing sockets after a preset time.

Post Reply