Page 1 of 2

update data to thingspeak

Posted: Sun Jun 26, 2016 10:22 am
by jiemde
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

Re: update data to thingspeak

Posted: Sun Jul 03, 2016 6:22 pm
by jiemde
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

Re: update data to thingspeak

Posted: Sun Jul 03, 2016 6:37 pm
by dhylands
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.

Re: update data to thingspeak

Posted: Sun Jul 03, 2016 6:46 pm
by jiemde
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

Re: update data to thingspeak

Posted: Sun Jul 03, 2016 7:22 pm
by dhylands
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.

Re: update data to thingspeak

Posted: Wed Jul 06, 2016 9:39 am
by jiemde
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

Re: update data to thingspeak

Posted: Sat Aug 13, 2016 10:37 pm
by mnelsoneorm
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?

Re: update data to thingspeak

Posted: Thu Aug 25, 2016 9:38 pm
by quantalume
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]

Re: update data to thingspeak

Posted: Fri Aug 26, 2016 11:04 am
by jgmdavies
@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

Re: update data to thingspeak

Posted: Fri Aug 26, 2016 5:26 pm
by quantalume
[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.