Building your first 5G Edge application with Verizon ThingSpace

Log in to AWS
  • In this tutorial, you connect a CAT-M1 LTE-enabled IoT device to a 5G Edge API server on an Amazon EC2® instance in the Boston Wavelength Zone (us-east-1-wl1-bos-wlz-1).
     

    Requirements and getting started

    To build this tutorial, you will require a Verizon ThingSpace account for your IoT connectivity plan, the Monarch Go IoT device from our ThingSpace Marketplace, a Raspberry Pi® 4 device and an active Amazon Web Services® (AWS® ) account.

    1. First, make sure your AWS account has Wavelength Zones enabled. If you have not submitted your request to get access, please complete the sign-up form here.

    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. You will also need a Monarch Go Pi Hat which includes everything you need—including the LTE module— to plug directly onto the Raspberry Pi board

    4. While you wait for 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 white sticker attached to Monarch Go module)

    5. Upon shipment(s) arrival, follow the Raspberry Pi Getting Started Guide to boot the OS and then attach the Monarch Go Pi Hat to the board. For more information on configuring your board, visit a step-by-step guide here from the Avnet team

  • Configuring your headless Raspberry Pi setup

    1. 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)

    2. Download vim from the package manager:

      sudo apt-get install vim

    3. Create an empty file named SSH in the boot directory of the SD card (vim SSH)

    4. Create a new file named wpa_supplicant.conf, which tells the Raspberry Pi how to connect to your Wi-Fi network to enable a headless boot. Be sure to edit the ssid and psk with your Wi-Fi network name and its corresponding password:

      country=US  
      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev  
      update_config=1    
      network={  
      scan_ssid=1  
      ssid="your_wifi_ssid"  
      psk="your_wifi_password"  

    5. Edit the cmdline.txt file to change the console universal asynchronous transmitter/receiver (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. After this step, eject the SD card from your laptop and plug it back into your Raspberry Pi

    6. Use the native ARP protocol (arp -a) to find the address of your Pi on your local network. Alternatively, you can leverage ping (ping raspberrypi.local) to get the IP address if connected to your Wi-Fi network

    7. Upon retrieving the address of your Pi, ssh into the board. Remember to supply the default password of raspberry:

      ssh pi@<your-ip-address>

  • Configure the UART.

    1. Open the Raspberry Pi configuration page

    2. sudo raspi-config

    3. Select option Serial 5: Interfacing Options
    4. Select option P6: Serial 5 

    5. At the prompt "Would you like a login shell to be accessible over serial?" answer No 

    6. At the prompt "Would you like the serial port hardware to be enabled?" answer Yes 

    7. Select Finish to exit, and Yes to reboot the Raspberry Pi

    8. After rebooting, ssh into your Raspberry Pi as you did earlier.

  • Verify the connection to your LTE modem.

    1. To get started, download the minicom package, which is a text-based modem control and terminal emulator program:

    2. sudo apt-get update && sudo apt-get install minicom

    3. 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 LTE:

    4. echo 17 > /sys/class/gpio/export  
      echo out > /sys/class/gpio/gpio17/direction  
      echo 0 > /sys/class/gpio/gpio17/value  
      echo 16 > /sys/class/gpio/export  
      echo in > /sys/class/gpio/gpio16/direction  

    5. Establish the communication to the modem using minicom:

    6. minicom --device /dev/serial0

    7. Now that you have direct communication to the modem, verify that you can connect to the modem and that the modem can connect to the LTE network. Run the command AT+CEREG? and you should see an output generated that looks something like this:

    8. +CEREG: 2,1 "150B","00539391",7

    9. Exit minicom (CTRL-A + X)

  • Configure point-to-point protocol for the Monarch Go.

    1. To communicate over LTE, you need to enable the point-to-point (PPP) protocol by downloading the package (sudo apt-get install ppp) and adding a few additional files

    2. 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

    3. Next, we 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"

    4. Next, add a new file connect in the /etc/chatscripts/ directory that provides the AT commands for the connect chatscript. Then, 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"

    5. Edit the /etc/network/interfaces file and add the line auto ppp0 to the end of the file

    6. To configure ppp0 as the default network, 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 ppp0 (not wlan0)

    7. With the IP address of the pp0 interface, add the IP to the default route to your gateway:

      sudo route add default gw XXX.XXX.XX.X
      netstat -rn

    8. You’re all set! Your Raspberry Pi will now connect, by default, to the LTE modem

  • Configure your 5G Edge Flask server.

    To communicate to 5G Edge, you’ll need to enable a Wavelength Zone in a public subnet within a virtual private cloud (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.

    1. 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, view this tutorial using the CLI

    2. After configuring your infrastructure, ssh into the EC2 instance in the Wavelength Zone and open a new file app.py 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")

    3. Run the API server and terminate the session:

      nohup python api.py &

    4. Next, ensure that your endpoint is configured correctly. From the Raspberry Pi shell, download python3 and connect to the /test endpoint. Note that in the request URL, the public IP address of your endpoint is the carrier IP that you attached to the EC2 instance in the Wavelength Zone:
    5. sudo apt update
      sudo apt install python3
      python
      import requests
      r=requests.get("http://<your-carrier-ip>:5000/test") 
      print(r.text)

    6. Congratulations, your "Hello World!" application using ThingSpace and 5G Edge is complete!