Pi Router: Share Wifi over ethernet with Xenon

Has anyone been able to share wifi with a Particle device over ethernet - specifically Xenon + Ethernet shield?

Setup

  • Raspberry Pi 3 connected to internet over wifi
  • Particle Xenon + Ethernet shield connected to Pi over ethernet

Issue

I am trying with the following script, but it only keeps flashing one of the following

  • Cyan - where it is trying to connect but never does
  • Orange (red/yellow) - where it hits an error in the connection

It seems like it should be possible, right?

Code

#!/bin/bash

# Share Wifi with Eth device
#
#
# This script is created to work with Raspbian Stretch
# but it can be used with most of the distributions
# by making few changes.
#
# Make sure you have already installed `dnsmasq`
# Please modify the variables according to your need
# Don't forget to change the name of network interface
# Check them with `ifconfig`

ip_address="192.168.2.1"
netmask="255.255.255.0"
dhcp_range_start="192.168.2.2"
dhcp_range_end="192.168.2.100"
dhcp_time="12h"
eth="eth0"
wlan="wlan0"

sudo systemctl start network-online.target &> /dev/null

sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -o $wlan -j MASQUERADE
sudo iptables -A FORWARD -i $wlan -o $eth -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i $eth -o $wlan -j ACCEPT

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

sudo ifconfig $eth $ip_address netmask $netmask

# Remove default route created by dhcpcd
sudo ip route del 0/0 dev $eth &> /dev/null

sudo systemctl stop dnsmasq

sudo rm -rf /etc/dnsmasq.d/* &> /dev/null

echo -e "interface=$eth\n\
bind-interfaces\n\
server=8.8.8.8\n\
domain-needed\n\
bogus-priv\n\
dhcp-range=$dhcp_range_start,$dhcp_range_end,$dhcp_time" > /tmp/custom-dnsmasq.conf

sudo cp /tmp/custom-dnsmasq.conf /etc/dnsmasq.d/custom-dnsmasq.conf
sudo systemctl start dnsmasq
1 Like

Have you tried flashing a logging test app onto the Xenon with LOG_LEVEL_ALL and catching the serial output? It might help indicate what’s going on.

https://docs.particle.io/reference/device-os/firmware/xenon/#logging-levels

Here’s what I’d start with:

#include "Particle.h"

SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler(LOG_LEVEL_ALL);

void setup() {

}

void loop() {

}
1 Like

I haven’t, good idea!

1 Like