Internet of Things with Pycom and Adafruit IO

Chris just shared a new tutorial: “Internet of Things with Pycom and Adafruit IO”



We’re going from zero to hero. Starting from nothing we’ll get a WiPy communicating with Adafruit IO, an IoT service out on the Internet. We’ll be able to send data from the device to the cloud and control the device f…

Read more

1 Like

Hi Chris.

I’m having some issues with this code as it stops to update to adafruit.io after about 24 transmissions. My LoPy4 transmitts my the package and types “Done” but adafruit doesn’t seem to get it as it won’t show up in my line chart. If I reset my LoPy4 it starts to transmitt and adafruit displays the values but after 24 iterations it stops again, which leads me to belive that it’s something wrong with the umqtt?

Hi @Adam66556,

Have you made any changes to the code, besides credentials?

Yeah a couple but I solved the issue by letting it publish 15 values then I put it into deepsleep for 10 milliseconds. Then it “resets” and starts to publish again. It´s not a pretty solution but it works fine!

Thanks for your quick answer anyway!

/Adam

Ok, everything sounds normal then. Like all public-facing APIs, there are rate limits. You can find Adafruit’s here

There are better ways to deal with rate limiting than putting the device to sleep (but if you are happy, then no need to change!). Three methods come to mind:

  • Check each response. If there is no success message, just wait for 10 seconds (or some arbitrary time) and try again. You could bake in some features to check if there are other factors at play by checking response codes, etc. Crude though effective.

  • millis() could be used alongside some other wizardry to determine when the 30/minute threshold is hit during a burst of packets. You could delay the exact time needed between each burst, although the process might end up being a blocking-type call (nothing else happens until it’s complete).

  • A more elegant method would be to load up your data into an array, set a flag which signals a timer interrupt to begin sending data. The interrupt will burst up to 30 messages instantly, servicing each response and managing rate limiting automatically. When the data has been fully TX’d, clear the flag so that new data can be queued up by the main program. This would allow your code to continue operating as normal, doing tens of millions of other things in-between.

If someone builds an elegant timer based solution, please do share it here :slight_smile:

How long does it take to upload umqtt.py? Seems to be 10s of minutes?

Hi Andrew,

It should take no more than a second or two. It’s no different than any other file being uploaded.

Still going. Creating lots of dir/packages/pymakr/node_modules/*

And still going.

I’m clearly overlooking something :slight_smile: How did it go in the end?

Took another hour Graham. I have no idea why, as the directories appeared to be there already.

I am very frustrated at this stage. See my post requesting professional help.

Cheers

Andrew Ritchie

Chris did this step-by-step @17:20 in the video. It’s likely you’ve done something differently.

@18:35 the upload takes around 3-4 seconds for that specific file, the device resets and REPL is ready within moments after that. Chris hits run on the Adafruit demo script, and the device is connected to adafruit.io within a couple of seconds.

Yes I can see that. Frustrating when it doesnt work for me

hey chris!
I want to enter 10101 and then print led on or off accordingly. where 1 is on and 0 is off. But could your please clarify what is b in the code below( b"on"). i am not able to get results properly because of that.

print((topic, msg))          # Outputs the message that was received. Debugging use.
if msg == b"ON":             # If message says "ON" ...
    pycom.rgbled(0xffffff)   # ... then LED on
elif msg == b"OFF":          # If message says "OFF" ...
    pycom.rgbled(0x000000)   # ... then LED off
else:                        # If any other message is received ...
    print("Unknown message") # ... do nothing but output that it happened.
2 Likes

Hi Shatakshi,

Welcome to the forum!!

The b"Text goes here" is a specifier used by python to ensure that a variable or string is the datatype ‘bytes’ rather than a string.
Usually a radio module (WiFi, LoRa, etc) will spit out something in this type.

What were you having trouble with?

PS: If you’re ever unsure what type something is you can use the function type(<YOUR VARIABLE HERE>) to get it printed out in the REPL. i.e. run your code, it can crash or hang (ctrl+c to interupt) thne use the function.

1 Like

Hello Chris,

I know this project is a bit old but I have a little problem…
I would like to do the same as you but I only have a wipy 3.0 and a pysense v1.1 module.
I followed step by step and I have a problem when I am connected to my adafruit account:

‘‘Guru Meditation Error of type LoadProhibited occurred on core 0. Exception was unhandled’’

thank you in advance =)