visit
We’ll assume that you’ve completed the steps from the first part of our eScooter series already. For a broader overview of this project, check out the first article here.
In the previous article, we were able to get our IoT eScooter sending data to the SORACOM cloud within just a few minutes. After we collect our data, we will need a way to remotely control and manage our eScooter based on the information we collected.
To do that, we need a tool to access and manage our IoT devices. It also needs to be secure despite a remote connection, so that it will be difficult for malicious hackers to tamper with the electric scooter but also allow us to send commands to it regardless of location. Once again, Soracom’s diverse range of services has one suited for our purpose: . This service lets us expose a TCP port for a limited time through the SORACOM Air SIM card, which we’ll use to control the connected Raspberry Pi. In this article, we’ll walk you through how we set up Napter on the Raspberry Pi, and how we used it to remotely manage the electric scooter.On the Soracom console, simply click the SIM you would like remote access to. Click the Actions button to reveal a drop down menu.
Click On-demand Remote Access.
Under Port to expose, enter 22. You can also change the Access allowed for timeout so that the port will automatically close after a certain length of time. This will make sure someone else using your computer after you cannot access the Raspberry Pi through SSH after the port times out. To further limit access to the port, you can enter in an IP address range.
Since an IP address identifies your computer to other computers, entering an address or address range here will restrict access to only those computers whose IP address fall within the range. This field defaults to the IP address of the computer used to connect to the website, so we’ll leave it blank. You can add more addresses in this field if you want another user to have access to the Raspberry Pi’s SSH (i.e. another admin).Note that you’ll have to change
to user
to login as the pi
user on the Raspberry Pi. pi
$ ssh -p {port} pi@{ip}
$ git clone [email protected]:DevinMui/soracom-escooter-device.git
$ pip install -r requirements.txt
In this repository, we have a set of scripts that connect to different Soracom services. For the web server, we can use the aptly named
napter.py
script to run a Flask web server on port 5000. $ python3 napter.py
With this command, we’ll now have a web server up and running! Using it, we’ll be able to control our scooter by sending HTTP requests and view scooter data.
GET /unlock
will unlock our scooter, GET /lock
will lock our scooter, and GET /
will show the scooter information. Neat!//{ip}
Luckily, the Bluetooth interface exposes this lock feature which we take advantage of in the program. To lock your device, you can send an HTTP
GET
request to the //{ip}/lock
. For example, using cURL$ curl //{ip}/lock
$ curl //{ip}/unlock
Because of its ease of use, SORACOM Napter has proven to be a useful service for remotely managing our cellular-connected IoT eScooter. We were able to access our server in just a few minutes. Most importantly, Napter takes care of security for us. Security is always a serious and difficult challenge when building an IoT device, and the electric scooter is no exception.
Napter’s ability to give only a select few IP ranges access to SSH and HTTP gives us ease of mind; we don’t have to worry about hackers breaking into the electric scooter and running commands without our consent. We could see a service like Napter being used in other IoT applications where security is paramount, like in asset monitoring and payment systems.In the next and last article of our four part series, we’ll demonstrate how all these services can work in conjunction with one another. We’ll create an AWS Lambda application hooked up to a MongoDB database to communicate with our electric scooter and wrap the series up with a client-side app built with React Native to enable surge pricing on scooters. See you next time!