The NanoPI Neo is a tiny $8 Linux computer available at FriendlyARM.
With a wide variety of accessories to interface with the real world, the NanoPi Neo can be an affordable but powerful IoT device.
Setting up your NanoPi
You can refer to FriendlyARM's instructions to setup your NanoPi, although here I present a simplified procedure:
Download PiFiller or Win32DiskImager and flash the .img file to an SD card (min 8GB of size)
Insert the SD card and boot the NanoPI with an Ethernet cable attached to your router.
Find the IP address assigned to your NanoPI: I typically use nmap from the command line, but you can also try looking at your router's client list.
Nmap IP Lookup:
Router's IP Lookup (Linksys router):
Connecting the NanoPi to Ubidots using Python
Now that we have the IP address, we can ssh into the NanoPi:
ssh root@10.85.4.193
User Name: root
Password: fa
Let's upgrade some packages and install pip, Python's packet manager:
sudo apt-get update
sudo apt-get install python-pip python-dev build-essential
Let's install these libraries:
requests: to make HTTP requests from Python to Ubidots
pyspeedtest: to measure the Internet speed from Python
pip install requests pyspeedtest
Ready to code!
Create a Python script:
nano ubi_speed_tester.py
And copy this code into it:
#!/usr/bin/python
import pyspeedtest
import requests
st = pyspeedtest.SpeedTest()
payload = {'Download': round(st.download()/1000000,2) , 'Upload': round(st.upload()/1000000, 2), 'Ping': round(st.ping(),2)}
r = requests.post('http://industrial.api.ubidots.com/api/v1.6/devices/NanoPi/?token=YOUR-UBIDOTS-TOKEN-HERE', data=payload)
Make sure to replace your Ubidots account token in the request URL.
Let's test the script:
python ubi_speed_tester.py
You should see a new device in your Ubidots account with three variables: Download, Upload and Ping:
Optional Step: Rename the Device and Variables
The names of the variables created are the same as the API labels, which are the IDs used by the API. This doesn't mean their names can't be changed, so I'd recommend changing the names of the devices and variables them to make them look better:
nanopi --> "Nano Pi Neo"
download --> "Download Speed"
upload --> "Upload Speed"
ping --> "Ping"
You can also add the units to each variable:
Create a Crontab to run the script every x minutes
Now that we tested the script we can set it to run automatically every x minutes. For this purpose we'll use Linux Cron tool.
1- Make the file executable:
chmod a+x ubi_speed_tester.py
2- Create a crontab
For some reason, the command “crontab -e” didn’t work out of the box, so I installed cron manually:
sudo apt-get install cron
then type:
“crontab -e”
and add the line
* * * * * python /root/ubi_speed_tester.py
to run the script every minute.
3- Reboot and Check your Data in Ubidots
Reboot the NanoPI
reboot
wait for a minute and then go to Ubidots to start seeing the results every minute:
Now that your data is in Ubidots, you can create dashboards and events. Here'a an example:
Bar chart widget
I also created two events: one to notify me if the Internet is slow, and another one to notify my if there's no Internet at all!
Value-based Event
Activity-based Event
Wrap up
Now put your NanoPi in a safe place behind your router and never worry again about wondering wether your ISP is providing the right service or not!