Skip to content


Repository files navigation


Arduino --[serial]--> Raspberry Pi --[web socket]--> Webserver (can also be on Pi) --[web socket]--> HTML5 Webpages

This repo contains a basic framework which allows JSON encoded data to be transfered from an Arduino (or other serial capable dev board) to locally hosted website (on a Raspberry Pi). It uses web sockets to provide realtime updates. This code was required as part of a larger project whcih can be found here:

Basic Setup

First of all I am going to assume you have a Raspberry Pi 3 with Raspbian installed and setup to connect to the internet. Older models of the Pi will work, but if you intend to use the Pi's browser to display a page, it is worth using the latest model.

First job is to make sure the file system is expanded to use the full capacity of the SD Card

  • Open terminal and type “raspi-config”.
  • Choose the “expand Filesystem” option and reboot the Pi

Launch command line and run the following to insure the system is up-to-date

  • sudo apt-get update

Next make sure you have the Epiphany browser installed

  • sudo apt-get install epiphany-browser

Check you have Python 3 and Pip installed

  • sudo apt-get install python3-pip

Make a new directory for the web server and move into it

  • mkdir ~/www
  • cd ~/www

Download the project code from github

Move into the directory

  • cd ocean-scan

Install all the python requirements

  • sudo pip3 install -r requirements.txt

Copy all the files from the from useful_tools to the raspberry pi desktop

  • sudo cp useful_tools/*.sh ~/Desktop

You must then make the usefull tools executable

  • sudo chmod +x ~/Desktop/*.sh

That's it, now we can launch the services.

You can either run:

  • python3 --prod &
  • sudo python3 —prod

or double click on the new icons on the desktop and choose execute in terminal

Once the server is up and running you can open the browser and go to localhost to see the website or from a remote machine you can enter the Raspberry Pi's IP address. The IP address can be discovered by double clicking on the "whats_my_ip" useful tool now on the desktop

Access Point Setup (Raspberry Pi 3 Only)

If you want people to be able to access the hosted web pages via WiFi you can setup the Pi3 to act as a local Access Point. This section was modified from

First install the two packages required

  • sudo apt-get install dnsmasq hostapd

Now we need to set a static IP address for wlan0

  • sudo nano /etc/dhcpcd.conf
  • Add the following to the bottom of the file:
interface wlan0  
    static ip_address=

Next we need to prevent wpa_supplicant from running and interfering with setting up wlan0 in access point mode.

  • sudo nano /etc/network/interfaces
  • Comment out the line that looks like:
allow-hotplug wlan0  
iface wlan0 inet manual  
   wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

So it looks like this

allow-hotplug wlan0  
iface wlan0 inet manual  
#   wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Restart dhcpcd

  • sudo service dhcpcd restart

Configure HostAPD

  • sudo nano /etc/hostapd/hostapd.conf
# This is the name of the WiFi interface we configured above.

# Use the nl80211 driver with the brcmfmac driver.

# This is the name of the network.

# Use the 2.4GHz band.

# Use channel 6.

# Enable 802.11n.

# Enable WMM.

# Enable 40MHz channels with 20ns guard interval.

# Accept all MAC addresses.

# Use WPA authentication.

# Require clients to know the network name.

# Use WPA2.

# Use a pre-shared key.

# The network passphrase.

# Use AES, instead of TKIP.

We can check if it's working at this stage by running sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf. If it's all gone well thus far, you should be able to see to the network Pi3-AP! If you try connecting to it, you will see some output from the Pi, but you won't receive and IP address until we set up dnsmasq in the next step. Use Ctrl+C to stop it.

We also need to tell hostapd where to look for the config file when it starts up on boot

  • sudo nano /etc/default/hostapd
  • find the line #DAEMON_CONF=""
  • replace it with DAEMON_CONF="/etc/hostapd/hostapd.conf"

Configure DNSMASQ

First move the config file out of the way

  • sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

Now make a new one

  • sudo nano /etc/dnsmasq.conf
  • paste the following into the file
# Use interface wlan0  

# Bind to the interface to make sure we aren't sending things elsewhere  

# Forward al domains to local webserver

# Assign IP addresses between and with a 12 hour lease time 

One of the last things that we need to do before we send traffic anywhere is to enable packet forwarding.

  • sudo nano /etc/sysctl.conf
  • remove the # from the beginning of the line containing net.ipv4.ip_forward=1
  • save and reboot it:
  • sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

Start the services

  • sudo service hostapd start
  • sudo service dnsmasq start

Finally reboot the Pi

  • sudo reboot

Now you should be able to connect to the Pi via WiFi. Navigate to http://ocean.scan in the browser and you should see the website.


No description, website, or topics provided.






No releases published