Bigiot ============== Bigiot is an IoT cloud platform that makes it more convenient for you to communicate with smart devices. Through the Internet, you can chat with your smart devices, send commands, and view real-time data in the form of dialogue, remote control, etc., set alarm conditions according to actual needs, and notify users through APP, email, SMS, Weibo, WeChat, etc. .. figure:: /_static/external/1540363897144665.jpg :width: 550 :align: center Bigiot architecture - Bigiot platform communication protocol: https://www.bigiot.net/help/1.html Connecting the mPython Board to Bigiot -------------------------------------- Preparation +++++++++++++++++++++ * Before use, you need to first register an account at Bigiot https://www.bigiot.net and add a smart device. * In the program, you need to use the bigiot mPython library, which you can get from https://github.com/labplus-cn/awesome-mpython/tree/master/library. Upload bigiot.py to the file system. Device Communication ++++++++++++++++++++++++ .. literalinclude:: /_static/products/mpython-s3/_static/examples/IoT/bigiot.py :caption: bigiot simple communication example :linenos: Before connecting to the Bigiot platform, you need to make sure the mPython Board is connected to the Internet. When instantiating the device ``Device(id,api_key)``, the smart device information of Bigiot is used, ``ID`` and ``API KEY``. Set the say communication callback function ``say_callback(f)``. f(msg,id,name) callback function, the ``msg`` parameter is the received message, the ``id`` parameter is the sending device ID, and the ``name`` parameter is the device name. ``check_in()`` is the device online function; you can see the device's connection status on the Bigiot platform. The above example sets the callback function and prints out the data received by the say communication. Client Sending Messages to the mPython Board ++++++++++++++++++++++++++++++++++++++++++++ Bigiot supports communication between multiple clients and devices, such as browsers, WeChat mini programs and official accounts, and APP (Android). .. figure:: /_static/products/mpython-s3/_static/image/tutorials/IoT/bigiot_1.gif :align: center Browser side .. figure:: /_static/products/mpython-s3/_static/image/tutorials/IoT/bigiot_2.gif :align: center :width: 500 WeChat mini program mPython Board Sending to the Device or Client +++++++++++++++++++++++++++++++++++++++++++++ Device ~~~~~~~~~ You can add multiple smart devices on the Bigiot platform at the same time. As long as the smart device is online and you know the device's ``ID``, you can send messages to the smart device. Send a message to the device with ID: 7947:: >>> device.say(device_id = 7947, msg = 'hello I am mPython') Client ~~~~~~~~~ To send a message to a web client or WeChat or other clients, you can view your user ID in the platform's "Personal Information":: >>> device.say(user_id = 5600, msg = 'hello I am mPython') Group ~~~~~~~~~ You can also set up multiple smart devices into a group on the platform and send messages to the group. This way, all members of the group can receive the message, similar to the IP multicast function:: >>> device.say(group_id = 145, msg = 'hello I am mPython') ``say(user_id, group_id, device_id, msg)`` This function is used for the dialogue of a device or client. The ``user_id``, ``group_id``, and ``device_id`` parameters are the user ID, group ID, and device ID respectively. Choose the parameter to use according to the dialogue object. ``msg`` is the dialogue message, of type string. Sending Data to the Interface +++++++++++++++++++++++++++++ Send the mPython Board's light data to the interface:9564:: while True: val=light.read() device.update(9564,str(val)) sleep(1) Bigiot provides an interface for collecting real-time sensor data and will draw charts. update(id, data) is the data upload function. ``id`` is the interface ID, and the ``data`` parameter is the uploaded sensor data. Note that this type is a string. If it is an int, it needs to be converted to str. Also, data should not be sent too quickly; there should be at least an interval of more than 1 second. Voice Assistant ------------------ Bigiot can also connect to Tmall Genie and Baidu Voice Assistant, with Bigiot devices acting as clients. They receive voice commands sent from the server, realizing the application of voice control of smart home. Method for Tmall Genie to Bind and Control Bigiot Devices +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ For the Tmall Genie binding method, refer to the tutorial: https://www.bigiot.net/talk/359.html