Posts: 4
Joined: Thu Feb 15, 2018 8:09 am

Pi to Pi communication over Local network

Thu Feb 22, 2018 12:33 pm


I am working on a similar project with a pi zero outside with some sensors on temp etc etc and a master pi which display all the data from zero pi to master pi. one way you can do this is by using samba on both pis to access a remote folder. I was going to set up remote sharing a folder on both pis and saving a .txt file to a spare synology nas drive but i would of thought you can do this between pis. Il have to admit i haven't tried this yet as i am still trying to get a few sensors plus getting the blasted dht11 sensor to work without data errors! but i dont see why this wouldn't work tbh. Setting up samba on raspberry pi.

you can save the data to a .txt file using python on one pi and get the other to read it and display information.

Example for ds18b20 temp module i been working on.

import os
import glob
import time
import datetime

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
f = open(device_file, 'r')
lines = f.readlines()
return lines

def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c, temp_f

def write_temp():
Data ="%Y-%m-%d %H:%M:%S") << a timestamp so you know when the reading was taken
dataAsInt = (read_temp())
dataAsString = str(dataAsInt)
fb = open('/home/pi/test2','a+') << change this to your samba location
fb.write("Time: " + str(Data) + "\n")
fb.write("Temp: " + dataAsString + "\n")

while True:

User avatar
Posts: 34762
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Pi to Pi communication over Local network

Fri Feb 23, 2018 7:04 am

Code: Select all

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
Remove those two lines.


Code: Select all

to your /boot/config.txt file and reboot.
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

Posts: 4
Joined: Thu Feb 15, 2018 8:09 am

Re: Pi to Pi communication over Local network

Fri Feb 23, 2018 8:46 am

Thanks for the heads up on the code ^^ :)

I have just checked writing a file to nas drive and while i couldn't get it to work using samba it works through nfs(different type of protocol) so you might want to give that a look up. Above code was running fine and storing values on nas drive so from their you could run whatever you want really if you program it into python.

lots information on google how to setup nfs etc on raspberry pi and how to make it auto mount on boot.

Return to “Automation, sensing and robotics”