SMesh is a sensor mesh network ("smesh") that performs long duration environmental sensing for sustainability research at Stanford.
A smesh node (or "snode") consists of a sensor payload plus a Meshtastic board that can relay readings using long range LoRa radio.
Snodes run a stable version of Meshtastic firmware with small modifications.
To access this firmware:
- Clone the firmware fork, i.e.
git clone https://github.com/josdo/meshtastic-firmware.git
- Follow https://meshtastic.org/docs/development/firmware/build/ to set up PlatformIO, a tool to build firmware from source.
Note: at step 3, pick
heltec-v3
from the list of options given.
- Go to: Raspberry Pi Software
- Download and install Raspberry Pi Imager.
- Insert your SD card into your computer or laptop.
- Open Raspberry Pi Imager.
- Click on the CHOOSE OS box, then select:
Raspberry Pi OS (other)
- Scroll down and select:
Raspberry Pi OS (Legacy, 32-bit) Lite
- Click on the CHOOSE STORAGE box and select your SD card.
- Click on the Settings icon in the bottom right corner, then follow the steps:
- Set hostname to
smeshX
(where X represents the number of the current system). - Tick the Enable SSH box.
- Set the username and password:
- Username:
pi
- Password:
smesh
- Username:
- Configure wireless LAN:
- SSID: Name of your WiFi network
- Password: Password of your WiFi network
- Wireless LAN country:
US
- Click SAVE.
- Set hostname to
- Click WRITE to begin writing the OS to the SD card.
- Once the Raspberry Pi OS has been installed, remove the SD card from your computer and insert it into your Raspberry Pi.
- Power the Raspberry Pi by connecting a micro USB cable to the PWR IN slot (connected to a battery pack or wall outlet).
- A green LED should light up near the PWR IN slot to indicate that the Raspberry Pi is ON.
- After a couple of minutes, the Raspberry Pi should be connected to your local WiFi network.
- Ensure your computer/laptop is connected to the same network.
- Open a Terminal and enter the command:
- During the first SSH connection, you may get the following error:
- If you see this error:
- Go to your user folder on your computer/laptop.
- Find a folder named
.ssh
. - Open the file named
known_hosts
and delete its content, then save. - Try connecting again with:
- When asked "Are you sure you want to continue connecting?", enter:
yes
. - Enter the password:
smesh
. - Once you see the prompt starting with
pi@smeshX
, you have successfully connected to the Raspberry Pi via SSH.
- Once connected via SSH, start by running the following commands:
sudo apt update sudo apt upgrade
- Install Python pip:
sudo apt install python3-pip
- Install Git:
sudo apt install git -y
- Clone the project's GitHub repository:
git clone https://github.com/smesh-stanford/smesh.git
- Open a different Terminal and upload the
credential.json
file from your own local directory to the Raspberry Pi by entering the command:(e.g. if the credentials.json file is stored in your local Downloads directory:scp /local/path/to/credentials.json [email protected]: /home/pi/smesh/snode
scp ~/Downloads/credentials.json [email protected]: /home/pi/smesh/snode
, where X in smeshX represents the number of the current system). - Once the upload has been completed, close this Terminal and go back to the previous one (where the SSH connection to the Raspberry Pi was established).
- Navigate to the
snode
directory:cd ./smesh/snode
- Install required dependencies:
pip3 install -r requirements.txt
- Create a data directory:
mkdir data
- In its default stage, the code will store any upcoming data packet to this data directory (absolute path:
/home/pi/smesh/snode/data
). In some cases, the user may want to change the name of the data directory to help with data management. In such case, the path to the data directory needs to be changed in the read_aqi.py, start_read_aqi.sh and upload_to_gdrive.py scripts located in/smesh/snode/scripts
:- read_aqi.py: From line 46 - 76, all the path arguments in the log_to_csv() function need to be changed to the new data directory path. For instance, if the user created a different data directory named data_pepperwood, all path arugments in the log_to_csv() function would be changed to:
f’/home/pi/smesh/snode/**data_pepperwood**/{nodeid}_bme688.csv’
- start_read_aqi.sh: Line 7, Change the path in the last line from
~/smesh/snode/**data**/read_aqi_stdouterr_log.txt
to the new data directory path (e.g.,~/smesh/snode/**data_pepperwood**/read_aqi_stdouterr_log.txt
) - uploading_to_gdrive.py: Change the path in ****Line 33 in the main function, to the new data directory path (e.g.
'/home/pi/smesh/snode/**data_pepperwood'**
)
- read_aqi.py: From line 46 - 76, all the path arguments in the log_to_csv() function need to be changed to the new data directory path. For instance, if the user created a different data directory named data_pepperwood, all path arugments in the log_to_csv() function would be changed to:
- Give execute permissions to the script start_read_aqi.sh:
chmod +x ~/smesh/snode/scripts/start_read_aqi.sh
- Open the cron table editor:
crontab -e
- Enter
1
to select the nano text editor. - Scroll to the bottom and add the following two lines (the number
5
in the second line indicates the time in minutes between uploads):@reboot ~/smesh/snode/scripts/start_read_aqi.sh */5 * * * * /usr/bin/python3 ~/smesh/snode/scripts/upload_to_gdrive.py
- Press
Ctrl + X
to exit. - Type
Y
and pressEnter
to save changes. - Run the command:
python3 read_aqi.py /dev/ttyUSB0
- The Cron Unix-based job scheduler should now be active, running the
read_aqi.py
andupload_to_gdrive.py
scripts to upload data to Google Drive.
-
Restart the Cron Unix-based job scheduler:
sudo service cron restart
-
Check the status of the Cron Unix-based job scheduler:
systemctl status cron
-
Test the
read_aqi.py
script for errors:- Navigate to the script directory:
cd ~/smesh/snode/scripts/
- Run the script without providing a serial port:
python3 read_aqi.py
- If the only error shown is similar to the following, it means all dependencies are correctly installed:
- Next, run the script with the USB0 port:
python3 read_aqi.py /dev/ttyUSB0
- If you get an error indicating that the port cannot be found, reconnect the Meshtastic or reboot the Raspberry Pi:
reboot
- After reboot, reconnect via SSH:
- Enter the password:
smesh
.
- Navigate to the script directory:
snode
is a Python package that contains all dependencies and code to read from snodes.
Files are organized into three directories:
- One-off scripts go into
snode/scripts
- Reusable code that scripts can import go into
snode/snode
- Tests for reusable code go into
snode/tests
To run any Python code:
- Install Poetry by following https://python-poetry.org/docs/#installing-with-pipx
- Enter the package you're using, e.g.,
cd snode
- Install the Python dependencies the code needs, i.e.,
poetry install
- Run a Python script, i.e.,
poetry run python PATH/TO/SCRIPT.PY