Websocket and MultiWii serial code to control a quadcopter, running on a Raspberry Pi
Note: All development and testing was done on a RaspberryPi 2 B+, in 2016. So be warned, things might not work exactly the same now.
- The first thing to do is to create a hosted Wi-Fi network. To accomplish this we use
isc-dhcp-server
andhostapd
isc-dhcp-server
serves as the DHCP server for our Wi-Fi networkhostapd
serves as access point management, essentially making a Wi-Fi card into a router
- Now for communication with our MultiWii device. I have a C library with the MSP protocol, and I use a backbone library
libserialport
libserialport
is downloaded from their git repository, and installedcMultiWii
, my MSP implementation is downloaded from the git repository. This will be compiled later
- Websocket communication is needed next. I use the
websocketpp
library, implemented in this repo.websocketpp
is not installed. It is a header-only library (.hpp), and is compiled each time (with the intention of improving performance)
- Compiling websocket.cpp in this repo will build the executable that will recieve commands from a remote control, and then relay them to the MultiWii. It compiles the
websocketpp
library which takes along time, and thecMultiWii
library which is quick to compile.
- Download/clone this repo
- Run
setup_pi_software.sh
, which will installlibserialport
,isc-dhcp-server
,hostapd
, and downloadcMultiWii
,websocketpp
. It will also compile the websocket server- You need to check to see if your MultiWii is
/dev/ttyUSB0
. Check the troubleshooting section for more information
- You need to check to see if your MultiWii is
- Since your network configuration and device might be different, your
/etc/network/interfaces
,/etc/default/isc-dhcp-server
, and/etc/dhcp/dhcpd.conf
files are not automatically modified. - Add the following configuration to your
/etc/network/interfaces
file in order forhostapd
to work. Also, remove any reference towpa_supplicant
, as it causes issues withhostapd
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.10.1
netmask 255.255.255.0
gateway 192.168.10.1
- Add the following configuration to your
/etc/default/isc-dhcp-server
file in order forisc-dhcp-server
to know what device to use
INTERFACES="wlan0"
- Add the following configuration to your
/etc/dhcp/dhcpd.conf
file in order forisc-dhcp-server
to know what subnet to use
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.1 192.168.10.30;
}
- You need to ensure
wlan0
andhostapd.conf
are correct. check the troubleshooting seciton for more information
- I would suggest a reboot after all of the installation process
- To start up the hosted network and the websocket, run
sudo ./piquadserver.sh
- To schedule everything to start up automatically on boot, edit
/etc/rc.local
with something like...cd /home/path/to/piquad
./piquadserver.sh &
.- rc.local is called automatically on startup.
- Check troubleshooting for more help
- To find your wireless interface, run
ifconfig
- To find your USB device, run
dmesg | grep ttyUSB
and look for what number it is- Once you find your device, you will need to edit line 4 of
configure_port.c
withincMultiWii
to reflect the proper device. You will have to recompile.
- Once you find your device, you will need to edit line 4 of
- If your wireless interface is not
wlan0
, then you will have to change it in yourinterfaces
file, and inhostapd.conf
- Check
/etc/hostapd/hostapd.conf
for hostapd configurations, and make sure they match yourinterfaces
configuration - If
hostapd
is throwing errors similar to:n180211: Could not configure driver mode
... then you probably need to kill the instance of hostapd already running.- Run
ps -A
to view all active processes - Find the process ID number for
hostapd
sudo kill <process ID>
will kill hostapd and hopefully resolve the issue
- Run
- If there are any problems with
isc-dhcp-server
, try runningsudo journalctl -u isc-dhcp-server.service
to look for errors - If you need to recompile at any time, just run
make
at the top level of this repository