Skip to content

Instantly share code, notes, and snippets.

@jywarren
Last active July 6, 2021 06:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jywarren/ce82d8c6ec3a05e591b7767d1a33c176 to your computer and use it in GitHub Desktop.
Save jywarren/ce82d8c6ec3a05e591b7767d1a33c176 to your computer and use it in GitHub Desktop.
# /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="ieee80211", ACTION=="add|change", ATTR{macaddress}=="b8:27:eb:ff:ff:ff", KERNEL=="phy0", \
RUN+="/sbin/iw phy phy0 interface add ap0 type __ap", \
RUN+="/bin/ip link set ap0 address b8:27:eb:ff:ff:ff"
# /etc/hostapd/hostapd.conf
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
beacon_int=100
auth_algs=1
wpa_key_mgmt=WPA-PSK
ssid=00-PiCamera
channel=11
wmm_enabled=0
macaddr_acl=0
hw_mode=g
wpa_passphrase=publiclab
interface=ap0
wpa=2
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP
country_code=
## Rapberry Pi 3 specific to on board WLAN/WiFi
#ieee80211n=1 # 802.11n support (Raspberry Pi 3)
#wmm_enabled=1 # QoS support (Raspberry Pi 3)
#ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] # (Raspberry Pi 3)
# interfaces(5) file used by ifup(8) and ifdown(8)
# /etc/network/interfaces
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo usb0 ap0 wlan0
#auto lo usb0
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
pre-up ifup ap0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
pre-down ifdown ap0
iface main inet dhcp
allow-hotplug ap0
iface ap0 inet static
pre-up iw phy phy0 interface add ap0 type __ap
pre-up ip link set ap0 address b8:27:eb:50:13:09
post-down iw dev ap0 del
address 172.24.1.1
netmask 255.255.255.0
hostapd /etc/hostapd/hostapd.conf
allow-hotplug usb0
iface usb0 inet manual
#iface usb0 inet static
# address 192.168.7.2
# netmask 255.255.255.0
# network 192.168.7.0
# broadcast 192.168.7.255
# gateway 192.168.7.1
Checklist:
1. basic pi camera web interface via P&C
2. ssh
3. ethernet gadget: https://learn.adafruit.com/turning-your-raspberry-pi-zero-into-a-usb-gadget/ethernet-gadget
- change /etc/network/interfaces to allow sharing back connection
4. welcome page at /index.hml w/ questions
- redirect to welcome page: https://raspberrypi.stackexchange.com/questions/41369/wifi-hotspot-with-redirect-to-html/41370
- https://raspberrypi.stackexchange.com/questions/58026/open-splash-page-after-connecting-to-wifi-hotspot?rq=1
- change raspimjpeg to ~/www/camera from ~/www/html in rc.local
https://raspberrypi.stackexchange.com/questions/29496/captive-portal-using-dnsmasq
5. display ip address on welcome page & output into /ip-address.html
6. ability to change hostname from welcome page: https://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/
- https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md
- https://github.com/billz/raspap-webgui - web-based config
7. save SD to a .img -- https://raspberrypi.stackexchange.com/questions/8305/how-to-make-an-image-img-from-whats-on-the-sd-card-but-as-compact-as-the-or#8314
7b. resize to fit on an 8gb card: http://www.instructables.com/id/How-to-BackUp-and-Shrink-Your-Raspberry-Pi-Image/
8. run raspivid on startup: `RaspiVid -f` and https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/, https://raspberrypi.stackexchange.com/questions/14398/autostart-videostream-without-logging-in 'su - pi -c "RaspiVid -f"'
- this won't work while raspimjpeg is running
- try using vlc to stream the produced video?
9. set up streaming: https://publiclab.org/questions/warren/12-05-2017/how-can-we-stream-video-to-spectralworkbench-org-or-infragram-org-from-a-raspberry-pi-camera
10. CORS on the Pi for streaming - https://enable-cors.org/server.html - OR run software on the Pi itself
Ideas:
* change WiFi pwd via welcome page
* change hostname via welcome page
* mount SD card via USB Gadget
* be both a WiFi hotspot and a member of a WiFi network:
- https://howtoraspberrypi.com/create-a-wi-fi-hotspot-in-less-than-10-minutes-with-pi-raspberry/
- and also https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/
- forum: https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=138730
- https://raspberrypi.stackexchange.com/questions/63841/rpi-zero-w-as-both-wifi-client-and-access-point
- EXACT: https://albeec13.github.io/2017/09/26/raspberry-pi-zero-w-simultaneous-ap-and-managed-mode-wifi/
## HOTSPOT SCRIPT
```
sudo apt-get install dnsmasq hostapd
sudo apt-get install git-core vlc npm curl
# install nvm
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install node
nvm use node
# link ~/www to /var/www and do bad things with permissions
ln -s /var/www/ www && chmod -R 777 www
# install infragram
cd www && git clone https://github.com/publiclab/infragram && cd infragram
npm install
# install welcome page index.html
# install wifi webgui - https://github.com/billz/raspap-webgui
wget -q https://git.io/voEUQ -O /tmp/raspap && bash /tmp/raspap
```
FILES CHANGED
/etc/network/interfaces
/etc/rc.local
/etc/wpa_supplicant/wpa_supplicant.conf
==============
RESOURCES
CAMERA
http://alligator.local/camera/cam_pic.php?time=1520532463091
vlc -vvv /dev/shm/mjpeg/cam.jpg # kind of works!!! but doesn't refresh; let's run from a URL as motion jpeg maybe
http://www.circuitbasics.com/raspberry-pi-zero-ethernet-gadget/
Find Raspberry PI address on local network
All raspberry devices MAC addresses started with B8:27:EB.
So, on *nix systems, this can be accomplished by executing the following command:
sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
where 192.168.1.* will be your local network mask. You will get an answer like:
Nmap scan report for raspberrypi.localnetwork.lan (192.168.1.179)
The 192.168.1.179 is the Raspberry Pi IP address on you network.
#!/bin/sh -e
#
# /etc/rc.local
#
# This script is executed at the end of each multiuser runlevel.
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
echo $_IP > /var/www/ip-address.html
fi
#START RASPIMJPEG SECTION
mkdir -p /dev/shm/mjpeg
chown www-data:www-data /dev/shm/mjpeg
chmod 777 /dev/shm/mjpeg
sleep 4;su -c 'raspimjpeg > /dev/null 2>&1 &' www-data
if [ -e /etc/debian_version ]; then
sleep 4;su -c 'php /var/www/html/schedule.php > /dev/null 2>&1 &' www-data
else
sleep 4;su -s '/bin/bash' -c 'php /var/www/html/schedule.php > /dev/null 2>&1 &' www-data
fi
#END RASPIMJPEG SECTION
sleep 30;
ifdown wlan0
service hostapd start
ifup wlan0
# connect hotspot clients to wlan0
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -s 172.24.1.0/24 ! -d 172.24.1.0/24 -j MASQUERADE
# attempt to get all the above running at once:
sleep 10;
ifdown --force wlan0 && ifdown --force ap0 && ifup ap0 && ifup wlan0
# redirect incoming requests to welcome page
# disable until we get wlan0 working
#iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 172.24.1.1:80
#iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 172.24.1.1:80
systemctl restart dnsmasq
exit 0
# /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="NetworkName"
psk="password"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment