1.3 What Data is Transferred between APP & Pico?

  1. From APP to Pico

    Let’s take a look at what kind of data Pico will get from the APP. Print data directly in on_receive.

    Note

    • Open the 1.3_ws_test_print.py file under the path of euler-kit\esp8266 or copy this code into Thonny, then click “Run Current Script” or simply press F5 to run it.

    • Don’t forget to click on the “MicroPython (Raspberry Pi Pico)” interpreter in the bottom right corner.

    • For detailed tutorials, please refer to Open and Run Code Directly.
      • Each time you rerun the code, you need to connect your device’s Wi-Fi to my_esp8266, then turn on SunFounder Controller and reconnect.

    from ws import WS_Server
    import json
    import time
    
    NAME = 'my_esp8266'
    
    ## Client Mode
    # WIFI_MODE = "sta"
    # SSID = "YOUR SSID HERE"
    # PASSWORD = "YOUR PASSWORD HERE"
    
    ## AP Mode
    WIFI_MODE = "ap"
    SSID = ""
    PASSWORD = "12345678"
    
    
    ws = WS_Server(name=NAME, mode=WIFI_MODE, ssid=SSID, password=PASSWORD)
    ws.start()
    
    def on_receive(data):
        print(data)
    
        # output
    
        # input
    
    ws.on_receive = on_receive
    
    def main():
        print("start")
        while True:
            ws.loop()
    
    main()
    

    You will see the data for each area in the Shell. When we drag the Slider in the H area, the value of the H area will change. This is because we only add one control widget (H area). The widget in the G area is not used for control but only for show.

    sc_ws_test_data

    We can also add other control widgets, and use the same method to view the values ​​sent by these widgets to Pico.

    You can get the value of the corresponding widget by just using the label. As shown below, print the value of the H widget:

    Note

    • Open the 1.3_ws_test_print_h.py file under the path of euler-kit\esp8266 or copy this code into Thonny, then click “Run Current Script” or simply press F5 to run it.

    • Don’t forget to click on the “MicroPython (Raspberry Pi Pico)” interpreter in the bottom right corner.

    • For detailed tutorials, please refer to Open and Run Code Directly.
      • Each time you rerun the code, you need to connect your device’s Wi-Fi to my_esp8266, then turn on SunFounder Controller and reconnect.

    from ws import WS_Server
    import json
    import time
    
    NAME = 'my_esp8266'
    
    ## Client Mode
    # WIFI_MODE = "sta"
    # SSID = "YOUR SSID HERE"
    # PASSWORD = "YOUR PASSWORD HERE"
    
    ## AP Mode
    WIFI_MODE = "ap"
    SSID = ""
    PASSWORD = "12345678"
    
    
    ws = WS_Server(name=NAME, mode=WIFI_MODE, ssid=SSID, password=PASSWORD)
    ws.start()
    
    
    def on_receive(data):
        print(data['H'])
    
        # output
    
        # input
    
    
    ws.on_receive = on_receive
    
    def main():
        print("start")
        while True:
            ws.loop()
    
    main()
    
    >>> %Run -c $EDITOR_CONTENT
        Connecting
        WebServer started on ws://192.168.4.1:8765
        start
        Connected from 192.168.4.3
        34
        50
        87
    
  2. From Pico to APP

    Use the send_dict function to show the value in G Widget.

    Note

    • Open the 1.3_ws_test_input.py file under the path of euler-kit\esp8266 or copy this code into Thonny, then click “Run Current Script” or simply press F5 to run it.

    • Don’t forget to click on the “MicroPython (Raspberry Pi Pico)” interpreter in the bottom right corner.

    • For detailed tutorials, please refer to Open and Run Code Directly.
      • Each time you rerun the code, you need to connect your device’s Wi-Fi to my_esp8266, then turn on SunFounder Controller and reconnect.

    from ws import WS_Server
    import json
    import time
    
    NAME = 'my_esp8266'
    
    ## Client Mode
    # WIFI_MODE = "sta"
    # SSID = "YOUR SSID HERE"
    # PASSWORD = "YOUR PASSWORD HERE"
    
    ## AP Mode
    WIFI_MODE = "ap"
    SSID = ""
    PASSWORD = "12345678"
    
    
    ws = WS_Server(name=NAME, mode=WIFI_MODE, ssid=SSID, password=PASSWORD)
    ws.start()
    
    led = machine.PWM(machine.Pin(15))
    led.freq(1000)
    potentiometer = machine.ADC(28)
    
    def on_receive(data):
    
        # output
    
        # input
        value=potentiometer.read_u16()
        ws.send_dict['G'] = value # the value show on the G area
    
    
    ws.on_receive = on_receive
    
    def main():
        print("start")
        while True:
            ws.loop()
    
    main()
    

    After running the code, turn the potentiometer and you will be able to see the value of the G widget change.

  3. Widget List

  • Control Widgets

sc_app_control_widget

  • Show Widgets

sc_app_show_widget