Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

Help editing Python to integrate with IO
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Help editing Python to integrate with IO

by dpowrie on Wed Jan 27, 2016 8:27 am

Hi All,

Very new, and spent many hours trying to figure this out, so apologies if the answer is out there...

I'm trying to set up a Raspberry Pi to measure temperature, motion (with a PIR) and turn on a camera when triggered.

I've currently been able to get the temperature up and running with https://learn.adafruit.com/dht-humidity ... ll-updated

But it would seem that the Adafruit IO platform would be a better way to do this as with time and experience I could add the other elements I'm after.

It seems from the tutorials that it simply involves adding a few lines of code to a basic measurement python script, but being so new I'm not sure exactly how to do it.

Any chance someone can point me to a demonstration of python before and after integration with Adafuit IO?

I figure if I can get the temperature logging going, the rest should be much easier!

Thanks in advance,

DP

dpowrie
 
Posts: 4
Joined: Wed Jan 27, 2016 6:33 am

Re: Help editing Python to integrate with IO

by jwcooper on Fri Jan 29, 2016 2:16 pm

Here is a python example. You should be able to just drop this in after installing the python library:
https://github.com/adafruit/io-client-p ... /simple.py

Then just send your temp/motion/camera values to a feed for each one.

Install info here:
https://github.com/adafruit/io-client-python

jwcooper
 
Posts: 677
Joined: Tue May 01, 2012 9:08 pm

Re: Help editing Python to integrate with IO

by dpowrie on Wed Feb 03, 2016 7:57 am

Thanks JW,

Chipped away at it, but I think I need to go away and learn more Python!

Cheers,

DP

dpowrie
 
Posts: 4
Joined: Wed Jan 27, 2016 6:33 am

Re: Help editing Python to integrate with IO

by tdack on Thu Feb 04, 2016 6:50 am

A really simple python example:

Code: Select all | TOGGLE FULL SIZE
import paho.mqtt.publish as publish

msgs =[{'topic': "some_user/feeds/temperature", 'payload': 27, 'retain': false},
       {'topic': "some_user/feeds/motion", 'payload': "Yes!", 'retain': false}]

publish.multiple(msgs,
                 hostname="io.adafruit.com",
                 port="1883",
                 auth={'username': "some_user", 'password': "aio key"})

That will publish to two feeds on io.adafruit,com - temperature and motion

tdack
 
Posts: 6
Joined: Sun Jan 17, 2016 5:38 pm

Re: Help editing Python to integrate with IO

by dpowrie on Thu Feb 04, 2016 11:34 pm

Thanks again to the forum. Will try when I get a chance.

dpowrie
 
Posts: 4
Joined: Wed Jan 27, 2016 6:33 am

Please be positive and constructive with your questions and comments.