Skip to content

Instantly share code, notes, and snippets.

@jasonacox
Last active June 1, 2024 06:22
Show Gist options
  • Save jasonacox/91479957d0605248d7eadb919585616c to your computer and use it in GitHub Desktop.
Save jasonacox/91479957d0605248d7eadb919585616c to your computer and use it in GitHub Desktop.
Set up RaspberryPi as Network Router to Powerwall Gateway

RaspberryPi - Powerwall Router

This will set up a Raspberry Pi to connect to a Tesla Powerwall Gateway (TEG) and bridge that connection to the ethernet connected LAN.

Network Configuration

 ___________________          __________________________           _______________
[ Powerwall Gateway ]        [      Raspberry Pi        ]         [      Host     ]
[       TEG         ]  WiFi  [__________________________]   LAN   [ Linux/Mac/Win ]
[   WiFi: TEG-xxx   ] <----  [ 192.168.91.x | 10.0.1.55 ] <-----> [   10.0.1.65   ]
[   192.168.91.1    ]        [  WiFi (dhcp) |  Ethernet ]         [      LAN      ]
 ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾          ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾           ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
 

Raspberry Pi

  1. Create or edit /etc/wpa_supplicant/wpa_supplicant.conf:
network={
        ssid="TEG-xxx"
        psk="password"
}
  1. Restart Networking and Test
sudo systemctl restart networking

# Test
ifconfig wlan0
ping -c 1 192.168.91.1
  1. Set up IPv4 Routing and Reboot
# Add IP Forwarding - Uncomment net.ipv4.ip_forward=1
sudo sed -i -e '/^#net\.ipv4\.ip_forward=1/s/^#//' /etc/sysctl.conf
sudo sysctl -w net.ipv4.ip_forward=1

# Restart
sudo reboot

Host

On the host, you need to add a route to use the Raspberry Pi as a gateway to get to the Powerwall Gateway.

# Linux
sudo ip r add 192.168.91.0/24 via 10.0.1.55

# MacOS
sudo route add -host 192.168.91.1 10.0.1.55

# Test
ping -c 1 192.168.91.1
curl -ik https://192.168.91.1
@jasonacox
Copy link
Author

Does the IP Forwarding give the Tesla Gateway access to my local network?

Yes, but the traffic can't make it back to the Gateway unless you add the route back to the Powerwall via the RPi.

Alternative: If you are using your RPi to poll the Powerwall and just present the data (via Dashboard, API, etc) to your LAN, you don't need to add the IP forwarding, just Steps 1 and 2. The Powerwall would only have access to your RPi in that case.

I’m using two wifi adapters in my raspberry Pi

That would work as well. Would you be willing to share your setup?

@jasonacox
Copy link
Author

It turns out that this isn't really needed. You can set up a connection to the Powerwall TEG IP address direct from the host with a route to 192.168.91.1 via the LAN IP address of the Powerwall (e.g. 10.x.x.x):

# Linux
sudo ip r add 192.168.91.0/24 via 10.x.x.x

# MacOS
sudo route add -host 192.168.91.1 10.x.x.x

# Test
ping -c 1 192.168.91.1
curl -ik https://192.168.91.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment