Skip to content
Paul Sokolovsky edited this page May 24, 2017 · 8 revisions

Building

Currently, building MicroPython Zephyr port with network sockets support requires special branches both for Zephyr and for MicroPython:

  1. git clone https://github.com/pfalcon/zephyr; git checkout master-micropython. Use git pull --rebase to update (branch rebased).
  2. git clone https://github.com/pfalcon/micropython; git checkout zephyr-socket2. Use git pull --rebase to update (branch rebased).
  3. Follow https://www.zephyrproject.org/doc/subsystems/networking/qemu_setup.html to bring up QEMU TAP/SLIP based local networking. To access Internet, you will need to setup NAT rules as described there too.
  4. Setup Zephyr environment for master-micropython per its docs.
  5. cd micropython/zephyr; make
  6. make run. If it doesn't start up, check your step 3.
  7. From another terminal, ping 192.0.2.1. If pings don't come thru, check your step 3.
  8. Switch back to QEMU terminal from step 6, and start playing!

Testing

Sample code, connecting to HTTP server on your local machine (Apache runs by default on many Linux machines, if not, install it):

import socket
s = socket.socket()
s.connect(("192.0.2.2", 80))
s.send(b"GET /foo HTTP/1.0\r\n\r\n")
s.recv(1000)

For further testing, DNS server/proxy running on the host (192.0.2.2) is required. A typical Ubuntu system runs dnsmasq proxy, but it doesn't pick up newly created network interfaces, so you need to restart it explicitly:

service dnsmasq restart
Clone this wiki locally