IoT & DevOps

Getting Started on ThingSpace with 5G Edge

Build your first IoT application at the edge with Verizon ThingSpace and AWS Wavelength

Verizon 5G Edge Blog
7 min readDec 15, 2020

Robert Belson, Corporate Strategy, Verizon

Josh Foster, Technical Solutions Engineer, AVNET

About this post

Over the past few weeks, you might have seen examples of how to build your first 5G Edge application with AWS Wavelength, or your first edge ML Inference app. But what about Internet of Things (IoT) applications?

In this tutorial, we document how to get your first CAT-M1 4G LTE-enabled IoT device up and running with a Raspberry Pi device and connect to 5G Edge.

Requirements and getting started

To build this tutorial, a Verizon ThingSpace account is required for your IoT connectivity plan, and you will need the Monarch Go IoT device from our ThingSpace Marketplace, a Raspberry Pi 4 device and an active AWS account.

  1. Start by making sure your AWS account has Wavelength Zones enabled. If you have not submitted your request to get access, please visit the sign-up form here to get started
  2. Next, purchase your Raspberry Pi 4 and ensure that you have a compatible SD card with the latest Raspberry Pi OS (32-bit)
  3. After purchasing the Raspberry Pi 4, make sure you have a USB-C charger (i.e., same as MacBook Pro 2017+) to power the device
  4. Now that you have the Raspberry Pi, you will need a Monarch Go Pi Hat, which has everything you need — including the 4G LTE module — to plug directly onto the Raspberry Pi board
  5. While you wait for your shipment, visit the ThingSpace Marketplace to activate your SIM card with a monthly data plan of your choice. (Note: Since you already have a Verizon-certified SIM in your Monarch Go, you will need the ICCID and IMEI values on the module. See the white sticker in image below)
  6. Once your shipment(s) arrives, follow the Raspberry Pi Getting Started with Raspberry Pi guide and then attach the Monarch Go Pi Hat to the board. The completed hardware setup should look something like the image below:

Configuring your headless Raspberry Pi setup

If you have a monitor, keyboard and mouse, feel free to skip this next step. You can plug the monitor, keyboard and mouse into the micro-HDMI and USB ports respectively, and boot the OS from there. However, for those who would prefer to SHH into the board directly, instructions are below.

  • Plug your SD card into your laptop (you may need an SD card to USB-C adapter) and then navigate to the boot directory on the SD card (cd ~/Volumes/boot)
  • Quick download vim from the package manager (sudo apt-get install vim)
  • Create an empty file named SSH in the boot directory of the SD Card (vim SSH)
  • Create a new file named wpa_supplicant.conf, which tells the Raspberry Pi how to connect to your Wi-Fi network (to enable headless boot)
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdet
update_config=1
network={
scan_ssid=1
ssid=”your_wifi_ssid”
psk=”your_wifi_password”
}
  • Edit the cmdline.txt file to change the console UART from primary UART to secondary UART (serial1), which the Monarch Go Pi Hat requires. Within that first line, change console=serial0 to console=serial1
  • Now the fun part: Find the IP address of your Pi on your local network, using the native ARP protocol (arp -a). Alternatively, you can leverage ping (ping raspberrypi.local) to get the IP address, if you are connected to your Wi-Fi network
  • Upon retrieving the address of your Pi (mine was 192.168.1.251), SHH into the board (ssh pi@192.168.1.251) and remember to provide the password, which is raspberry
  • Congrats, you’re in

Configuring the universal transmitter/receiver (UART)

  1. Open the raspberry Pi configs and enter sudo raspi-config
  2. Select option 5 — Interfacing Options
  3. Select option P6 — Serial 5
  4. At the prompt “Would you like a login shell to be accessible over serial?” answer No
  5. At the prompt “Would you like the serial port hardware to be enabled?” answer Yes
  6. Select Finish to exit and Yes to reboot the Raspberry Pi
  7. Log in again to your Raspberry Pi 4 B (ssh@you_ip_address) as you did earlier

Verifying the connection to your 4G LTE modem

  • To get started, download the minicom package, which is a text-based modem control and terminal emulator program (sudo apt-get update && sudo apt-get install minicom)
  • Next, configure the general-purpose input/output (GPIO) pins on your board, which adjusts the RTS/CTS signals you need for the Monarch Go to communicate over 4G LTE
echo 17 > /sys/class/gpio/exportecho out > /sys/class/gpio/gpio17/directionecho 0 > /sys/class/gpio/gpio17/valueecho 16 > /sys/class/gpio/exportecho in > /sys/class/gpio/gpio16/direction
  • Establish communication to the modem using minicom (minicom — device /dev/serial0)
  • Now that you have direct communication to the modem, you want to verify that you can connect to the modem — and that the modem can connect to the 4G LTE network. Run the command AT+CEREG?, and you should see an output generated that looks something like this:
+CEREG: 2,1 “150B”,”00539391",7
  • Exit minicom (CTRL-A + X). You’re now ready to connect to 5G Edge

Configuring Point-to-Point Protocol Monarch Go

  • To communicate over 4G LTE, you need to enable the PPP p by downloading the package (sudo apt-get install ppp) and adding a few additional files
  • Add a new file titled pp0 (sudo vim ppp0 /etc/network/interfaces.d/) with the following text, which creates the PPP network interface connection.
auto ppp0
iface ppp0 inet ppp
provider sequans
  • Next, you need to create a new file named sequans in the /etc/ppp/peers/ folder with the following contents:
/dev/serial0
115200
crtscts
-chap
pppd
by
debug
defaultroute
which
pppd
dump
local
lock
noauth
nodetach
noipdefault
usepeerdns
connect “/usr/sbin/chat -t6 -f /etc/chatscripts/connect”
disconnect “/usr/sbin/chat -t6 -f /etc/chatscripts/disconnect”
  • Then you need to add a new file connect in the /etc/chatscripts/ directory that provides the AT commands for the connect chatscript. You also need to add a new file disconnect in the /etc/chatscripts/ directory that provides the AT commands for the connect chatscript
#connect
TIMEOUT 30
ABORT ERROR
“” AT
OK AT+CGDATA=”PPP”,3
CONNECT “”
#disconnect
# This is the chat script used to hang up the Sequans Module
#
“” “\d\d\d+++\c”
  • Edit the /etc/network/interfaces file and add the following line (auto ppp0) to the very end of the file
  • To configure ppp0 as the default network, you need to find the IP address of the ppp0 interface (netstat -rn). The correct IP address will be the one with the Iface column indicating that it is of type pp0 (not wlan0)
  • Once you have the IP address of the pp0 interface, you need to add the IP to the default route to your gateway
sudo route add default gw XXX.XXX.XX.X
netstat -rn
  • You’re all set! Your Raspberry Pi will now connect, by default, to the 4G LTE modem

Configuring your 5G Edge Flask server

To communicate to 5G Edge, you’ll need to enable a Wavelength Zone in a public subnet within a VPC; attach a carrier gateway to the subnet; launch an EC2 instance; allocate a carrier IP address to our EC2; and run a Flask server to accept incoming HTTP traffic.

  • To provision your 5G Edge infrastructure, you’ll need the AWS CLI version 2 installed on your local machine. To launch an EC2 instance in a Wavelength Zone of your choice, take a look at this tutorial using the CLI
  • After configuring your infrastructure, open a new file app.py and add the following to accept GET request traffic over the test endpoint
from flask import Flask, jsonify
app=Flask(__name__)
@app.route(“/test”,methods=[“GET”])
def getTest():
return “Hello from 5G Edge!”
if __name__==’__main__’:
app.run(host=”0.0.0.0")
  • To run the server, run (nohup python api.py &) and terminate the session
  • To ensure that your endpoint is configured correctly, run the following from your Raspberry Pi:
sudo apt update
sudo apt install python3
python
Import requests
r=requests.get(“http://3.135.18.240:5000") #replace with carrier IP
print(r.text)
  • Congratulations! Your Hello World application using Thingspace and 5G Edge is complete

Bonus Round: Expanding your 5G Edge Flask server

  • Next, to build a more involved Flask server, let’s incorporate POST requests so the Pi can generate data and send to 5G Edge. To do so, edit the api.py file and replace the existing content with the following:
from flask import Flask,request,jsonify
import json
app = Flask(__name__)
metrics=[ #Illustrative scenario, assuming you have existing data
{
‘id’:1,
‘Data’:0.72
},
{
‘id’:2,
‘data’:0.74
}
]
@app.route(‘/’)
def hello_world():
return ‘Hello from 5G Edge!’
@app.route(‘/records’,methods=[‘POST’])
def create_record():
d=json.loads(request.data)
print(d)
metric={
‘id’: metrics[-1][‘id’]+1,
‘data’: d[‘point’]
}
metrics.append(metric)
return jsonify({‘metric’:metric}),201
if __name__ == ‘__main__’:
app.run(host=”0.0.0.0")
  • Lastly, within your Raspberry Pi SHH session, run the following few lines to generate data and send to 5G Edge. Please note that the post request is a simple attribute<>value pair in JSON; if you’d like to add additional attributes to the data object, make sure to reflect that in the create_record() function server-side
header={‘Content-Type’: ‘application/json’}
data={‘point’: ‘0.76’} #substitute 0.76 with any value of your choice!
r=requests.post(“http://3.135.18.240:5000/records",headers=header,data=data)
print(r.text)

The next step is to build a more involved application that takes advantage of the low-latency compute afforded by the Wavelength Zone. In my next post, I’ll take you through a simple outlier detection algorithm you can run in python (scikit-learn) to identify anomalies in the data generated from your IoT device (i.e., Raspberry Pi) to the cloud.

Acknowledgments

A huge thank you to Josh Foster at the AVNET team for helping to build out the Monarch Go documentation! Check out his original blog piece here to learn more.

--

--

Verizon 5G Edge Blog
Verizon 5G Edge Blog

Written by Verizon 5G Edge Blog

Powering the next generation of immersive applications at the network edge.

No responses yet