MENG XI Posted November 27, 2020 Report Share Posted November 27, 2020 This is MicroPython project developed using Ameba RTL8722. MicroPython is offically supported on Ameba RTL8722, so through this demo video, we will see how easy and fast it is to develop a simple server socket on Ameba, which would then control other peripheral to perform other tasks. Here we are using a client socket code running on PC to send a 'Hello, world' string via the WiFi network, Ameba receives it and if it is indeed 'Hello, world' then it will blink the LED. Check out the demo video down below, https://youtu.be/pEMkwvw-r18 Code used: #!/usr/bin/env python3 #PC Client code import socket HOST = '192.168.1.152' # The server's hostname or IP address PORT = 80 # The port used by the server with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) s.send(bytes('Hello, world','utf8')) #Ameba Code from machine import Pin from wireless import WLAN import time import socket wifi = WLAN(WLAN.STA) wifi.connect("MPSSID","upyameba") led = Pin("PB_4",Pin.OUT) s = socket.SOCK() port = 80 data = ' ' s.bind(port) s.listen() conn, addr = s.accept() while True: data = conn.recv(1024) print(data) if data == b'Hello, world': print('turn on LED 1') for i in range(6): led.toggle() time.sleep_ms(200) if not data: break Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.