示例#1
0
'''
# file sub.py
# brief         Set 'SERVER','CLIENT_ID'(this can be null),'IOT_pubTopic','IOT_UserName','IOT_PassWord'
#               download into mpython and run the file
#               You receive the message from server
# Copyright     Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
# licence       The MIT License (MIT)
# author        [LuoYufeng]([email protected])
# version       V1.0
# date          2019-10-8
'''
from siot import iot
import time
SERVER = "192.168.2.107"  #MQTT服务器IP
CLIENT_ID = ""  #在SIoT上,CLIENT_ID可以留空
IOT_pubTopic = 'xzr/001'  #“topic”为“项目名称/设备名称”
IOT_UserName = '******'  #用户名
IOT_PassWord = '******'  #密码

def WIFIconnect():
    import network
    ssid = "dfrobotYanfa"
    password = "******"
    station = network.WLAN(network.STA_IF)
    if station.isconnected() == True:
        print("Wifi already connected")
        return
    station.active(True)
    station.connect(ssid, password)
    while station.isconnected() == False:
示例#2
0
'''
# file pub.py
# brief         Set 'SERVER','CLIENT_ID'(this can be null),'IOT_pubTopic','IOT_UserName','IOT_PassWord'
#               download into pc or raspberryPi and run the file
#               You will send the message by seconds
# Copyright     Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
# licence       The MIT License (MIT)
# author        [LuoYufeng]([email protected])
# version       V1.0
# date          2019-10-8
'''
from siot import iot
import time
SERVER = "127.0.0.1"  #MQTT服务器IP
CLIENT_ID = ""  #在SIoT上,CLIENT_ID可以留空
IOT_pubTopic = 'xzr/001'  #“topic”为“项目名称/设备名称”
IOT_UserName = '******'  #用户名
IOT_PassWord = '******'  #密码
siot = iot(CLIENT_ID, SERVER, user=IOT_UserName, password=IOT_PassWord)
siot.connect()
siot.loop()
tick = 0
try:
    while True:
        siot.publish(IOT_pubTopic, "value %d" % tick)
        time.sleep(1)  #隔1秒发送一次
        tick = tick + 1
except:
    siot.stop()
    print("disconnect seccused")
示例#3
0
'''
# file getsub.py
# brief         Set 'SERVER','CLIENT_ID'(this can be null),'IOT_pubTopic','IOT_UserName','IOT_PassWord'
#               download into pc or raspberryPi and run the file
#               You will receive the message from server
# Copyright     Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
# licence       The MIT License (MIT)
# author        [LuoYufeng]([email protected])
# version       V1.0
# date          2019-10-8
'''
from siot import iot
import time
SERVER = "127.0.0.1"        #MQTT服务器IP
CLIENT_ID = ""              #在SIoT上,CLIENT_ID可以留空
IOT_pubTopic  = 'xzr/001'   #“topic”为“项目名称/设备名称”
IOT_UserName ='******'        #用户名
IOT_PassWord ='******'     #密码
def sub_cb(client, userdata, msg):
  print("\nTopic:" + str(msg.topic) + " Message:" + str(msg.payload))
siot = iot(CLIENT_ID, SERVER, user=IOT_UserName, password=IOT_PassWord)
siot.connect()
siot.set_callback(sub_cb)
siot.getsubscribe(IOT_pubTopic)
siot.loop()
try:
  while True:
    pass
except:
  siot.stop()
示例#4
0
'''
# file pub_sub_with_timer.py
# brief         Set 'SERVER','CLIENT_ID'(this can be null),'IOT_pubTopic','IOT_UserName','IOT_PassWord'
#               download into mpython and run the file
#               You will send the message by seconds and receive the message from server
# Copyright     Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
# licence       The MIT License (MIT)
# author        [LuoYufeng]([email protected])
# version       V1.0
# date          2019-10-8
'''
from siot import iot
from machine import Timer
import time
SERVER = "192.168.2.107"  #MQTT服务器IP
CLIENT_ID = ""  #在SIoT上,CLIENT_ID可以留空
IOT_pubTopic = 'xzr/001'  #“topic”为“项目名称/设备名称”
IOT_UserName = '******'  #用户名
IOT_PassWord = '******'  #密码
siot = iot(CLIENT_ID, SERVER, user=IOT_UserName, password=IOT_PassWord)

def WIFIconnect():
    import network
    ssid = "dfrobotYanfa"
    password = "******"
    station = network.WLAN(network.STA_IF)
    if station.isconnected() == True:
        print("Wifi already connected")
        return
    station.active(True)