Unforgiven11
Posts: 7
Joined: Fri Mar 25, 2016 10:13 am

Using sensor values of pi1 in python script on pi2

Mon Aug 15, 2016 11:39 am

Hi all,

I have a Raspberry Pi B (pi1) reading sensor values for temperature, air pressure and humidity of a BME280 via i2c. Now I want to work with these values on pi2 in the same network, e.g. display them on a displayotron hat from Pimoroni.
What is the best and easiest way to handle this?

Kind regards and thanks in advance

User avatar
joan
Posts: 15038
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using sensor values of pi1 in python script on pi2

Mon Aug 15, 2016 11:48 am

Best and easiest are both subjective terms.

How will you judge which solution is best?

How will you judge which solution is easiest?

I'm hesitant to spend time proposing any solution which might be dismissed as not best or not easiest.

Unforgiven11
Posts: 7
Joined: Fri Mar 25, 2016 10:13 am

Re: Using sensor values of pi1 in python script on pi2

Mon Aug 15, 2016 12:00 pm

So let me change my question for you: How would you do this?
Oh I forgot to mention that I use python on pi1 and want to use these values on pi2 also in a python script.

User avatar
B.Goode
Posts: 10547
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Using sensor values of pi1 in python script on pi2

Mon Aug 15, 2016 12:08 pm

Unforgiven11 wrote:So let me change my question for you: How would you do this?
Oh I forgot to mention that I use python on pi1 and want to use these values on pi2 also in a python script.
As a 'least effort ' proof of concept I would write a shell or python script on Pi1 to return the results, and invoke that script via ssh from Pi2. Using ssh secure keys will make this more elegant.

If that works there are python library modules that can be used to automate it.

Unforgiven11
Posts: 7
Joined: Fri Mar 25, 2016 10:13 am

Re: Using sensor values of pi1 in python script on pi2

Mon Aug 15, 2016 12:37 pm

B.Goode wrote:
Unforgiven11 wrote:As a 'least effort ' proof of concept I would write a shell or python script on Pi1 to return the results, and invoke that script via ssh from Pi2. Using ssh secure keys will make this more elegant.

If that works there are python library modules that can be used to automate it.
This doesn't seem as 'least effort' to me.
Isn't there a way to directly hand over the sensor readings from pi1 to pi2?

I read about pigpio/pigpiod but does this work for my question? The sensor readings on pi1 are done via the adafruit python module.

User avatar
joan
Posts: 15038
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using sensor values of pi1 in python script on pi2

Mon Aug 15, 2016 1:23 pm

I would use pigpio, but I would say that as I wrote it.

However that wouldn't help if the sensors are being read by non-pigpio software.

Another option would be to use MQTT, but again that might be a bit of a learning curve.

The simplest solution may be to use pigpio functions to read the sensors.

But we get back to the same problem. We don't know your abilities so can't judge what will be easiest or best.

User avatar
B.Goode
Posts: 10547
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Using sensor values of pi1 in python script on pi2

Mon Aug 15, 2016 2:11 pm

Unforgiven11 wrote:
This doesn't seem as 'least effort' to me.
Isn't there a way to directly hand over the sensor readings from pi1 to pi2?
When you find an easier way I hope you will share it here so that I can use it too.

As @joan, its developer, has explained, pigpio is an easy way to read and set gpio values remotely.

EDIT: Ignore this: But you have specified the use of i2c which is not a simple gpio status. There is a half-formed nugget of truth in there, but it is poorly expressed. @joan is the best person to believe regarding the pigpio library.
Last edited by B.Goode on Tue Aug 16, 2016 2:00 pm, edited 1 time in total.

Unforgiven11
Posts: 7
Joined: Fri Mar 25, 2016 10:13 am

Re: Using sensor values of pi1 in python script on pi2

Tue Aug 16, 2016 8:20 am

As I understand it pigpio will not work for i2c sensor reading.

MQTT sounds interesting, where do I get easy examples to start with?

User avatar
joan
Posts: 15038
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Using sensor values of pi1 in python script on pi2

Tue Aug 16, 2016 8:35 am

Unforgiven11 wrote:As I understand it pigpio will not work for i2c sensor reading.

MQTT sounds interesting, where do I get easy examples to start with?
I2C is fully supported by pigpio.

MQTT, Google for Pi tutorials or examples.

Return to “Beginners”