-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpub.py
32 lines (28 loc) · 915 Bytes
/
pub.py
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
import paho.mqtt.client as mqtt
from time import strftime, sleep
import csv
import glob, os
mqtt_username = "pi"
mqtt_password = "raspberry"
mqtt_broker_ip = "192.168.4.1"
port = 1883
# Callback Function on Connection with MQTT Server
# def on_connect( client, userdata, flags, rc):
# print ("Connected with Code :" +str(rc))
# client.publish(topic="LED", payload="00")
client = mqtt.Client()
# client.on_connect = on_connect
client.username_pw_set(mqtt_username,mqtt_password)
client.connect(host=mqtt_broker_ip, port=port, keepalive=60)
client.loop_start()
while True:
print("Switch to MANUAL mode\n -- turn light ON\n")
client.publish(topic="LED", payload="11")
sleep(30)
print(" -- now turn light OFF\n")
client.publish(topic="LED", payload="10")
sleep(30)
print("switch to AUTO mode\n")
client.publish(topic="LED", payload="00")
sleep(30)
client.loop_stop(force=False)