Guest User

Untitled

a guest
Dec 18th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. from network import WLAN
  2. from mqtt import MQTTClient
  3. import machine
  4. from machine import Pin
  5. import time
  6. import os
  7. import pycom
  8.  
  9. p_out = Pin('P9', mode=Pin.OUT) # g16 on expansion board
  10.  
  11. adc=machine.ADC()
  12. moistureSensor = adc.channel(pin='P19') #G6 on expansion board
  13.  
  14. wlan = WLAN(mode=WLAN.STA)
  15. wlan.connect("SmartRG7912", auth=(WLAN.WPA2, "seanpaul"), timeout=5000)
  16. while not wlan.isconnected():
  17. machine.idle()
  18. print("Connected to Wifin")
  19. time.sleep(2)
  20.  
  21. def settimeout(duration):
  22. pass
  23. def sub_cb(topic, msg):
  24. print(msg)
  25.  
  26. client = MQTTClient(client_id="14a55d9d-9fca-4fce-b9f0-9bfec84e821f", server="io.adafruit.com", user="capsProject", password="47f1d473707041829ad00da61f99da23", port=1883)
  27. client.settimeout = settimeout
  28. client.set_callback(sub_cb)
  29. client.connect()
  30. print("Connected to Brokern")
  31. client.subscribe(topic="capsProject/feeds/valve", qos=1)
  32.  
  33. while True:
  34. print(str(client.check_msg()))
  35. time.sleep(1)
Add Comment
Please, Sign In to add comment