Joselito in Discussions
上次活动时间: 2025-6-16

Bom dia se alguém puder me ajudar, meu código abaixo, não estou conseguintdo conectar o meu Esp8266 ao ThingSpeak, o erro tá na conexão. Estou usando o MicroPython e NodeMCU na plataforma Pytohn o sistema operacional Ubuntu 20 # DHT11 -> ESP8266/ESP32 # 1(Vcc) -> 3v3 # 2(Data) -> GPIO12 # 4(Gnd) -> Gnd import time, network, machine from dht import DHT11 from machine import Pin from umqtt.simple import MQTTClient print("Iniciando...") dht = DHT11(Pin(12, Pin.IN, Pin.PULL_UP)) estacao = network.WLAN(network.STA_IF) estacao.active(True) estacao.connect('xxxxxxx', 'xxxxxxxxx') while estacao.isconnected() == False: machine.idle() print('Conexao realizada.') print(estacao.ifconfig()) SERVIDOR = "mqtt.thingspeak.com" CHANNEL_ID = "XXXXXXXXXXXXXXXXX" WRITE_API_KEY = "XXXXXXXXXXXXXXXXXXXXX" topico = "channels/" + CHANNEL_ID + "/publish/" + WRITE_API_KEY cliente = MQTTClient("umqtt_client", SERVIDOR) try: while True: dht.measure() temp = dht.temperature() umid = dht.humidity() print('Temperatura: %3.1f °C' %temp) print('Umidade: %3.1f %%' %umid) conteudo = "field1=" + str(temp) + "&field2=" + str(umid) print ('Conectando a ThingSpeak...') cliente.connect() cliente.publish(topico, conteudo) cliente.disconnect() print ('Envio realizado.') time.sleep(600.0) except KeyboardInterrupt: estacao.disconnect() estacao.active(False) print("Fim.") ***************************************************************************************************** No shell aparece como resposta: MPY: soft reboot Iniciando... Conexao realizada. ('192.168.0.23', '255.255.255.0', '192.168.0.1', '8.8.8.8') Temperatura: 29.0 °C Umidade: 63.0 % Conectando a ThingSpeak... Traceback (most recent call last): File "<stdin>", line 38, in <module> File "umqtt/simple.py", line 67, in connect OSError: -2 linha 38 é cliente.connect() Erro ao conectar: cliente.connect() It appears you're connecting to an incorrect server, mqtt.thingspeak.com instead of mqtt3.thingspeak.com. Start by modifying this example. python ubuntu

关于 ThingSpeak

The community for students, researchers, and engineers looking to use MATLAB, Simulink, and ThingSpeak for Internet of Things applications. You can find the latest ThingSpeak news, tutorials to jump-start your next IoT project, and a forum to engage in a discussion on your latest cloud-based project. You can see answers to problems other users have solved and share how you solved a problem.