Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from network import WLAN
- from mqtt import MQTTClient
- import machine
- from machine import Pin
- import time
- import os
- import pycom
- p_out = Pin('P9', mode=Pin.OUT) # g16 on expansion board
- adc=machine.ADC()
- moistureSensor = adc.channel(pin='P19') #G6 on expansion board
- wlan = WLAN(mode=WLAN.STA)
- wlan.connect("SmartRG7912", auth=(WLAN.WPA2, "seanpaul"), timeout=5000)
- while not wlan.isconnected():
- machine.idle()
- print("Connected to Wifin")
- time.sleep(2)
- def settimeout(duration):
- pass
- def sub_cb(topic, msg):
- print(msg)
- client = MQTTClient(client_id="14a55d9d-9fca-4fce-b9f0-9bfec84e821f", server="io.adafruit.com", user="capsProject", password="47f1d473707041829ad00da61f99da23", port=1883)
- client.settimeout = settimeout
- client.set_callback(sub_cb)
- client.connect()
- print("Connected to Brokern")
- client.subscribe(topic="capsProject/feeds/valve", qos=1)
- while True:
- print(str(client.check_msg()))
- time.sleep(1)
Add Comment
Please, Sign In to add comment