3633 views|2 replies

96

Posts

0

Resources
The OP
 

Tmall Genie controls ESP8266 to light up LED lights [Copy link]

 

There is no connection between Tmall Genie and esp8266, so how to use Tmall Genie to control esp8266?


This tutorial uses the Scallop IoT platform (http://www.bigiot.xyz) to connect ESP8266 for Microython to Tmall Genie.

step:

1. After applying for a Scallop IoT platform account, create a new device and obtain information such as the device name, device user, and device key.

2. Flash the micropython firmware into esp8266

3. Upload the mqtt library (see attachment)

4. Upload main.py

5. ESP8266 connects to WiFi

6. Run main.py

from simple import MQTTClient
from machine import Pin,Timer

#led选择G4引脚控制
p4 = Pin(4, Pin.OUT, value=0)

# MQTT服务器地址域名
SERVER = "bigiot.xyz"
#设备ID,user是扇贝物联平台注册的用户
CLIENT_ID = "{{user}}_esp8266"
#订阅开关主题,user是扇贝物联平台注册的用户
TOPIC = b"{{user}}/{{user}}_esp8266"
#设备用户
username=''
#设备密钥:
password=''

def sub_cb(topic, msg):
  print((topic, msg))
  if msg == b"on":
    p4.value(1)
    print("1")
  elif msg == b"off":
    p4.value(0)
    print("0")


def main(server=SERVER):
  #端口号为:1883
  c = MQTTClient(CLIENT_ID, server,1883,username,password)
  c.set_callback(sub_cb)
  c.connect()
  c.subscribe(TOPIC)
  print("Connected to %s, subscribed to %s topic" % (server, TOPIC))
  try:
    while 1:
      c.wait_msg()
  finally:
    c.disconnect()

simple.py (6.26 KB, downloads: 39)




This content is originally created by EEWORLD forum user youxinweizhi . If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

Latest reply

Like, I just used Beike IoT to implement this function today.  Details Published on 2020-1-8 22:01
 
 

940

Posts

0

Resources
2
 
Like, I just used Beike IoT to implement this function today.

Comments

Try Scallop IoT, the platform is completely open source.  Details Published on 2020-2-4 11:03
 
 
 

96

Posts

0

Resources
3
 
wgsxsm posted on 2020-1-8 22:01 Like, I just used Shell IoT to implement this function today.

Try Scallop IoT, the platform is completely open source.

 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list