This page is being edited.
Script for receiving data from wall clock sensors. This script can be used to obtain information about the microclimate in the room. As an example, look at the bot.
Now Porfyry knows what microclimate is in the house.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import os import requests import json def read_sensors(): response = os.system("ping -c 1 " + "192.168.1.62") if response == 0: uri = 'http://192.168.1.62/readjson' #ip address ESP8266 try: result = requests.get(uri) result.raise_for_status() data = result.json() co2 = (data['sensors']['co2']) temp = (data['sensors']['bmet']) hum = (data['sensors']['bmeh']) press = (data['sensors']['bmep']) lux = (data['sensors']['tsllux']) micro_climate = 'carbon dioxide content = {}\n\ temperature = {}\nhumidity = {}\npressure = {}\nlighting = {}\n'\ .format(co2, temp, hum, press, lux) return micro_climate except: return 'Sensors not available' else: return 'ESP8266 not available' if __name__ == '__main__': print(read_sensors()) |
A script for checking connected devices to a home network. This script can be used to find out who is present at home and which devices are turned on. Since not all devices respond to a ping request, it is a more reliable way to see the status of the arp table on our Raspberry. You need to find out if the maс address of the device (such as a smartphone) is in the arp table.
Now Porfyry knows who is at home and what devices are working.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import subprocess import os import time def scan_arp(): #Table of mac addresses of devices in your home network device_mac = {'Igors_phone':'6c:c7:ec:78:24:04', 'Lenas_phone':'a0:c9:a0:a4:9d:2b', 'Ladas_phone':'20:f4:78:28:93:3c', 'TV':'d0:66:7b:de:b5:60', 'Igors_comp':'bc:85:56:e4:a3:85' } #I found this command on the Internet. That way the command quickly wakes up the devices in your home network and the arp table is quickly updated. process = subprocess.Popen('echo $(seq 254) | xargs -P255 -I% -d" " ping -W 1 -c 5 192.168.1.%\ | grep -E "[0-1].*?:"',stdout=subprocess.PIPE, encoding='utf8',shell=True) stdout = process.communicate() #print (stdout) #Wait until all devices are polled and the ARP table is updated time.sleep(20) process = subprocess.Popen('arp', stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8',shell=True) stdout, stderr = process.communicate() #print(stdout) m = '' for n in stdout.split(): if n == device_mac['Igors_phone']: m = m + 'Igor at home'+'\n' if n == device_mac['Lenas_phone'] : m = m + 'Lena at home'+'\n' if n == device_mac['Ladas_phone']: m = m + 'Lada at home'+'\n' if n == device_mac['Igors_comp']: m = m + 'Igors comp is on'+'\n' if n == device_mac['TV']: m = m + 'TV is on'+'\n' return m if __name__ == '__main__': print(scan_arp()) |