Close

Python Listener Code

A project log for Simple Temperature Monitor

ESP8266-01 + DS18b20

robRob 03/02/2017 at 23:230 Comments
#!/usr/bin/python

import socket, requests
from subprocess import call

UDP_PORT = 12345
UDP_IP = ""

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP,UDP_PORT))
print "Listening on UDP port: "+str(UDP_PORT)
while True:
        data, addr = sock.recvfrom(1024)
        print addr[0],data

        if data.find("->"):
                influxValueFind = data.find("->")+3
                influxValue = data[influxValueFind:influxValueFind+5]
                influxLoc = data[data.find("(")+1:data.find(")")]
                r=requests.post('http://10.0.1.202:8086/write?db=mydb', 'temperature,host=ESP00000,location=%s value=%s'%(influxLoc,influxValue))

Discussions