Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import gmtime, strftime
- import paho.mqtt.client as mqtt
- import sqlite3
- temperature_topic = "temperature"
- humidity_topic = "humidity"
- dbFile = "esp8266.db"
- # The callback for when the client receives a CONNACK response from the server.
- def on_connect(client, userdata, flags, rc):
- print("Connected with result code "+str(rc))
- # Subscribing in on_connect() means that if we lose the connection and
- # reconnect then subscriptions will be renewed.
- client.subscribe("temperature")
- client.subscribe("humidity")
- # The callback for when a PUBLISH message is received from the server.
- def on_message(client, userdata, msg):
- theTime = strftime("%Y-%m-%d %H:%M:%S", gmtime())
- # theTime = strftime("%H:%M:%S", gmtime())
- #print(msg.topic+" "+str(msg.payload))
- result = (theTime + "\t" + str(msg.payload))
- print(msg.topic + "\t" + result)
- if (msg.topic == temperature_topic):
- writeToDb(theTime, str(msg.payload))
- return
- if (msg.topic == humidity_topic):
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement