My idea for this project is to create a device similar to a medical alert button. This device can be used anywhere there is cellular service. The way I built this is more like a tracker, but to add an actual button would be a minor change.
The way it works is once it powered up, there is a cron job that will run a getdata.sh script every 5 mins. This script will call a GPS python script The GPS script will then get the coords, convert it to latitude and longitude in degrees, and out put the values in JSON format. The getdata.sh will then take that JSON output and upload it to Soracom Harvest where it will store the data.
Here is a sample of the JSON output
{ 'latitude' : 48.1173 , 'longitude': 11.5167 }
And here is what it looks like in Soracom dashboard
I had an issue retrieving the data from Soracom's Harvest. I tried a few different ways and still not able to get it. As you can see above, the data is there and can be viewed using Soracom's Data viewer.
The BuildFor the build, I'm not going to explain all the steps as there are other tutorials that will do a better job than I can so I will reference them instead.
Set Up the Raspberry Pi
- Download the Raspbian image to your PC.
- Follow these instructions to install Raspbian.
- Connect everything to the Pi, I connected a keyboard, mouse and monitor as it makes this job easier.
- Insert the SD card into the Pi.
- Power it up and finish the install.
The easiest way to do this is to follow these instruction. This will explain how to setup the dongle and how to make the necessary changes to the Pi to allow it to pickup the dongle every time its rebooted.
Connect the GPS Sensor
I used this image to make the necessary connection to my Raspberry Pi Zero. The image is taken from lokesh chandak site. It shows a Raspberry Pi 3, but the connections and instruction are the same.
Set Up Soracom's Harvest
I used these instruction to setup Harvest on Soracom. If you have your USB modem dongle set up correctly, after you set up Harvest, you should be able to run some of the examples at the bottom of the instructions.
Load the Software
At this point you should have a working Pi with the GPS connected. Now we need to load my software.
- Power up the Pi and log in. (I log in as Pi and use my home directory/home/Pi).
- Create a directory called GPS.
- Copy the the gps.py and getdata.sh to the /home/pi/gps directory ( make sure you have execute permission on the getdata.sh script.
- At this point you shouldn't need to change code. You should be able to run the getdata.sh and it should upload the GPS coords.
- If all works correctly, you can add the cron job to the crontab. the command is crontab -e then you just have to cut and paste the line listed in the cron job code section.
- I said it above, and one of the biggest issues was retrieving the data. I can do it using Soracom's data viewer, so I know the data is there. I tried a few different ways like sending a GET command using curl, but it wouldn't return my data. I also found another site on the developers soracom site, but I still couldn't get the data back. Not sure what is wrong at this point.
- Second issue is using a Raspberry Pi. The problem is there is no power management on a Pi. So this build really isn't practical unless you are using it connected to a good power source.
I would like to thank Soracom and Hackster for giving me the opportunity to build this project. I had a few issues with it, but in the end I was able to build a device that would update the location of the user. Even though I think it isn't practical to carry on a person because of the power requirements, it could be used on a vehicle or motor bike where it can be wired to a battery that is constantly getting charged.
Thanks,
Dana
Comments