Wifi Example

In this notebook, we show how to connect to a WiFi network.

For boards equipped with a USB interface, a WiFi dongle can be plugged into the board. Specifically a RALink WiFi dongle commonly used with Raspberry Pi kits is connected into the board. Using Linux calls and Python functions, we will determine the unique name of the dongle and then create a network entry for a known ssid/password pair.

For boards equipped with onboard WiFi module, we can follow the same process as well.

References: http://www.canakit.com/raspberry-pi-wifi.html

1. Create WiFi instance

Make sure:

  1. The USB WiFi module has been plugged in, or
  2. There is already an embedded WiFi module on board (e.g. Ultra96).

In [1]:
from pynq.lib import Wifi

port = Wifi()


Type in the SSID and password as instructed. It may take a while to establish the connection.


In [2]:
ssid = input("Type in the SSID:")
pwd = input("Type in the password:")
port.connect(ssid, pwd)


Type in the SSID:iphone_hotspot
Type in the password:12345678

3. Test connection

Ping 10 packets, then the following cell stops automatically. Notice there are only a few websites that accept ping.

The following cell assumes the default wireless interface wlan0.


In [3]:
! ping -I wlan0 www.yahoo.com -c 10


PING www.yahoo.com(media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4)) from 2600:380:4455:f5aa:d9be:7d77:2574:fb61 wlan0: 56 data bytes
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=1 ttl=50 time=278 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=2 ttl=50 time=136 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=3 ttl=50 time=182 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=4 ttl=50 time=92.7 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=5 ttl=50 time=132 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=6 ttl=50 time=130 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=7 ttl=50 time=146 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=8 ttl=50 time=136 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=9 ttl=50 time=141 ms
64 bytes from media-router-fp1.prod1.media.vip.gq1.yahoo.com (2001:4998:c:1023::4): icmp_seq=10 ttl=50 time=132 ms

--- www.yahoo.com ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9012ms
rtt min/avg/max/mdev = 92.740/151.020/278.769/47.309 ms

4. Reset connection


In [4]:
port.reset()