wow should i use mip.install? (trying to connect with adafruit server whith a micropython board) #12822
Unanswered
camp-easy
asked this question in
Using MicroPython
Replies: 1 comment
-
Please enclose code in triple backticks ("`" characters). That preserves indentation. Then show the traceback which will tell us which line of code is causing the error. Lastly please don't spam multiple messages about the same problem. I and others have already explained that the line mip.install("micropython-umqtt.simple") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
hi everyone, im using this code to make callback whit mqtt broker with adafruit server :
import cellular
import machine
import time
cellular.gprs("", "", "") # ("apn_name","username","password")
led_topic = "/feeds/stato"
sensor_topic = "/feeds/temperature"
led = machine.Pin(27,machine.Pin.OUT)
time_period = 6
Import mqtt (download client if necessary)
try:
from umqtt import simple
except ImportError:
import mip
mip.install("micropython-umqtt.simple")
from umqtt import simple
def cb(led_topic, msg): # Callback function
print('Received Data: Topic = {}, Msg = {}'.format(led_topic, msg))
recieved_data = str(msg,'utf-8') # Recieving Data
if recieved_data=="0":
led.value(0)
if recieved_data=="1":
led.value(1)
Report location
name = "a9g-micropython-board"
server = "io.adafruit.com"
port = 1883
username = ""
password = ""
client = simple.MQTTClient(name, server, port, username, password )
client.connect()
client.set_callback(cb) # Callback function
client.subscribe(led_topic) # Subscribing to particular topic
def send_sensor():
msg = "100"
print('Sending Data: Topic = {}, Msg = {}'.format(sensor_topic, msg))
client.publish(sensor_topic, msg)
while True:
for x in range(time_period):
for x in range(10):
client.check_msg()
time.sleep(0.1)
send_sensor()
but it's not working and i receive thi serror:
OSError: [Errno 110] ETIMEDOUT
does anyone know how to fix that? thank you in advance for the support
Beta Was this translation helpful? Give feedback.
All reactions