import os tfile=open("/sys/bus/w1/devices/28-000000d7970b/w1_slave") ttext=tfile.read() tfile.close() temp=ttext.split("\n")[1].split(" ")[9] temperature=float(temp[2:])/1000 print temperature
#MAC[#NAME][#LAT][#LNG][#ELE]\n #mac1#value1[#time1][#name1]\n ... #macN#valueN[#timeN][#nameN]\n ##
#MAC\n #mac1#value1\n #macN#valueN\n ##
#!/usr/bin/env python2 # -*- coding: utf-8 -*- # by Roman Vishnevsky aka.x0x01 @ gmail.com import socket # MAC . ! DEVICE_MAC = '0123456789012' # , 01 (02) mac SENSOR_ID_1 = DEVICE_MAC + '01' SENSOR_ID_2 = DEVICE_MAC + '02' # , float/integer sensor_value_1 = 20 sensor_value_2 = -20.25 # sock = socket.socket() # try: # sock.connect(('narodmon.ru', 8283)) # sock.send("#{}\n#{}#{}\n##".format(DEVICE_MAC, SENSOR_ID_1, sensor_value_1)) # # sock.send("#{}\n#{}#{}\n#{}#{}\n##".format(DEVICE_MAC, SENSOR_ID_1, sensor_value_1, SENSOR_ID_2, sensor_value_2)) # data = sock.recv(1024) sock.close() print data except socket.error, e: print('ERROR! Exception {}'.format(e))
#!/usr/bin/env python2 # -*- coding: utf-8 -*- import socket import os import fnmatch # MAC . ! DEVICE_MAC = 'FF:FF:FF:FF:FF:FF' # SENSOR_ID_1 = 'T1' SENSOR_ID_2 = 'T2' # temperature = [] IDs = [] for filename in os.listdir("/sys/bus/w1/devices"): if fnmatch.fnmatch(filename, '28-031652ddbdff'): with open("/sys/bus/w1/devices/" + filename + "/w1_slave") as fileobj: lines = fileobj.readlines() if lines[0].find("YES"): pok = lines[1].find('=') temperature.append(float(lines[1][pok+1:pok+7])/1000) IDs.append(filename) else: logger.error("Error reading sensor with ID: %s" % (filename)) temperature2 = [] for filename in os.listdir("/sys/bus/w1/devices"): if fnmatch.fnmatch(filename, '28-011563e8d2ff'): with open("/sys/bus/w1/devices/" + filename + "/w1_slave") as fileobj: lines = fileobj.readlines() if lines[0].find("YES"): pok = lines[1].find('=') temperature2.append(float(lines[1][pok+1:pok+7])/1000) IDs.append(filename) else: logger.error("Error reading sensor with ID: %s" % (filename)) sock = socket.socket() # try: sock.connect(('narodmon.ru', 8283)) # , sock.send("#{}\n#{}#{}\n#{}#{}\n##".format(DEVICE_MAC, SENSOR_ID_1, str(temperature)[1:-1], SENSOR_ID_2, str(temperature2)[1:-1])) # data=sock.recv(1024) sock.close() print data except socket.error, e: print('ERROR! Exception {}'.format(e)) print str(temperature)[1:-1] print str(temperature2)[1:-1]
crontab -e
and add this line to it:
*/10 * * * * sudo python /home/pi/narod.py
Source: https://habr.com/ru/post/401313/