Approved content
The content below is provided by a partner.
Extension for Kittenbot Wifi module
Make sure you have upgrade firmware of your WiFi module to v2.82 or higher.
<<<<<<< HEAD
a64a2a872ab456993aa3470864e4945b540a05d0
Connect wifi to the 2.4g band wireless network, connect to the MQTT server and subscribe to topics, try to send and receive messages. (KittenBot provides an MQTT server for debugging: https://iot.kittenbot.cn/)
kittenwifi.on_wifi_connected(function () {
basic.showIcon(IconNames.Yes)
})
input.onButtonPressed(Button.A, function () {
kittenwifi.mqtt_sethost("iot.kittenbot.cn", "node01")
})
input.onButtonPressed(Button.AB, function () {
kittenwifi.mqtt_publish_basic("/topicName", "message")
})
input.onButtonPressed(Button.B, function () {
kittenwifi.mqtt_subscribe_basic("/topicName")
})
kittenwifi.on_mqtt_topic_data(function (topic, data) {
basic.showString("" + topic + ":" + data)
})
kittenwifi.wifi_init(SerialPin.P2, SerialPin.P12)
kittenwifi.wifi_join("rrouter", "password")
WF CMD Argc Callback Argv...
WIFI_STATUS_CHANGED = 1,
MQTT_CONN = 2,
MQTT_DISCON = 3,
MQTT_PUB = 4,
MQTT_DATA = 5,
UDP_SETUP = 6,
UDP_DATA = 7
Sync with wifi module with wifi status change callback
WF 1 0 1
return
WF 2 0 1
WF 3 1 1 stat // wifistatus 1: other, 5: got ip
WF 3 1 1 5 192.168.0.123
Join dedicated access point with name and pass word
WF 52 2 52 ap pass
successful join would return wifi status 5, eg:
WF 3 1 1 5
Hostname for wifi module discover or name connecte or ping, need lan support
WF 9 1 9 name
No return
Get Ip address of wifi module
WF 8 0 22
return
WF 3 1 22 192.168.0.111
please refer callback mapping
WF 10 4 0 2 3 4 5
WF 15 2 15 hostname clientid
resend mqtt callback install after this command issued
WF 12 2 0 topic qos
qos set to 0 or 1 for now, other value may not be implemented
expect callback 5 when someone pub on this topic
WF 3 2 5 /hello hello world
WF 11 4 11 qos retain topic data
WF 13 4 13 topic data 1 1
Note: this command will get mqtt offline, you should hard reset module to bring it alive
WF 3 0 5 /hello 1234567890
Target ip and port (for both tx and rx)
WF 40 3 callback 192.168.0.2 5533 3
return
WF 40 clientNum 0
User should keep track of clientnum in the following process
WF 42 4 clientnum data
WF 41 1 cliennum helloworld
the restful client num is irrelevant to udp client num
WF 20 3 callback kittenbot.cn port(80) security(0 or 1)
return
WF 20 clientnum 0
WF 21 2 cliennum method(GET or POST) /api/xxx?
return, the maximum return limit to 256 bytes (64byte limit in microbit rx buffer). So, make sure you have a good api server :P
WF 23 2 clientnum code(20x or 40x) content
MIT
kittenwifi=github:Kittenbot/pxt-kittenwifi
kittenwifi=github:KittenBot/pxt-kittenwifi#v0.2.7