Introduction
This blog builds on what kevinkeryk did with he Monarch Go Starter Kit witht he Ultra96V2. We are going to establish a headless setup, setup a Point to Point Protocol with the Monarch Go Modem, and finally setup a IoTConnect demo over the estabished LTE Connection.
Version
Date | Version | Revision |
---|---|---|
17 August 20 | 01 | Initial Release |
Required Equipment
Raspberry Pi 4 B Headless Setup and Baseline Test
Operating System SD Card Setup
1. Take your 16GB microSD Card and connect it to your PC
2. Download the "Raspberry Pi OS (32-bit) with desktop and recommended software" by going to Link
3. You can then use a program such as Win32DiskImager or Etcher.io to flash the .img image onto the 16GB SD Card.
4. Leave the SD Card in your PC as some changes will need to be made.
Enable SSH Support via Wifi
1. Open the boot directory on the SD card you just imaged
2.Create a empty file named SSH in the boot directory of the SD Card
3.Make sure to remove any extension on this file, for instance in my case, I created the SSH file by creating a TXT file named SSH, I then enabled viewing extensions and removed it from the file. To enable viewing extension, follow this guide
4. Create a new file named wpa_supplicant.conf and add the following text into the file. Please note where is says your_wifi_ssid and your_wifi_password you must put your wifi SSID and 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. Similiary to the SSH file, make sure to remove the .txt extension from the end of the file.
Retarget the Default Uart
1. For the Raspberry Pi 4 B, the default UART (serial0) used by console for communicating with the SBC is the primary UART which is the same UART interface the Monarch Go Pi Hat needs to use. We will need to change our console UART from primary UART to secondary UART (serial1). Open the boot directory on the SD Card in the windows explorer. Open the cmdline.txt file using a text editor, change console=serial0 to console=serial1
See completed change in image below for reference. Make sure to save and exit the text editor
Hardware Setup
1. Set the Monarch Go Pi Hat Jumpers to Single Board Computer Operation
- J6 : 1-3 / 2-4
- J7 : 1-3 / 2-4
- J10 : No Connect
2. Connect the Monarch Go Pi Hat to your SBC 40 pin GPIO Raspberry Pi Hat
3. Insert the microSD Card into the Raspberry Pi 4 B and connect the power supply. The SBC should power on.
Connect the Raspberry Pi 4 B via SSH
1. Now that the board has powered on, you should have enabled SSH and automatically connect the board to your wireless network
2. Now the fun part of determing the IP address of your Raspberry Pi 4 B!
3. In my case I logged into my router and determined the IP address of the Raspberry Pi 4 B
4. You can refer to your router which should have information in regards to how to login to your router. Or do a quick google search on how to login to your router! If you can't find your raspberry pi IP address when you logged into the modem, you most likely left the extensions on your wapsupplicant.conf file on the sd card.
5. Now that we have determined the Raspberry Pi IP address in my case (192.168.0.29). Open a terminal in my case putty and type in the IP address, make sure the port is 22 and SSH is selected. Then select open to start your session.
7. You have successfully connected to the Raspberry Pi 4 B
8. You can now login to the Raspberry Pi using
- Username - pi
- Password - raspberry
Enabling Both UARTs
1.Earlier we changed the default console UART to the Seconday UART we must now enable the primary UART for the Sequans communciation.
2. Open the raspberry Pi configs enter sudo raspi-config
3.Select option 5 - Interfacing Options
4.Select option P6 - Serial
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 4 B
8. Relogin to your Raspberry Pi 4 B as you did earlier.
9.Type ls /dev to verify both serial interfaces are enabled.
10. Congrats, both Uarts are enabled!
Establishing a Baseline using Minicom
1.Lets use minicom to communicate the the Monarch Go modem. Lets first update existing archives and then install minicom
sudo apt-get update sudo apt-get install minicom
2. Let now configure the RTS/CTS signals on the Monarch Go. Run the following commands NOTE everytime you power down the board you will need to reconfigure these GPIO
a. RTS configure as an output with a value of 0
echo 17 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio17/direction echo 0 > /sys/class/gpio/gpio17/value
CTS configure as an input
echo 16 > /sys/class/gpio/export echo in > /sys/class/gpio/gpio16/direction
3. Lets establish the communication to the modem using minicom
minicom --device /dev/serial0
4. You now have direct communication to the modem. Run the command AT+CEREG? in the terminal to verify the connection to the modem and the modem to the Verizon network is established.
You will get somthing along the lines of this. The 1 boxed is red is what you need to look at. If this number is "1" you are successfully connect to the verizon network. If it is any other number your connection to Verizon is not established. Verify your modem is registered with Verizon thingspace along with verifing you are not in a dead spot for Verizon LTE connection.
5. Exit minicom. In the terminal enter the following
CTRL-A X
Select Yes to leave minicom
Setting up Point to Point Protocol with the Monarch Go Modem
We want to setup Point to Point Protocol with the Monarch Go Modem so it is referenced under linux as a standard wireless connection.
Adding PPP Infrastructure to the Raspberry Pi 4B OS
1. The first steps are to install Point-to-Point Protocol support under Ubuntu by installing the ppp related packages. I did this with the following command:
sudo apt-get install ppp
2. Next we need to create a new file named ppp0 file in the /etc/network/interfaces.d/ folder with text contents.
a. Run the following commands to create the file in the correct location
sudo touch ppp0 /etc/network/interfaces.d/
b. Now the ppp0 file is created, we need to edit the file and add the following text. Edit this file using a command line text editor such as nano or vi. Make sure to use sudo when using vi or nano. For information in how to use these see this link
auto ppp0 iface ppp0 inet ppp provider sequans
c. This new ppp0 file creates an automatic ppp network interface connection by utilizing the Seqans provider information that gets setup in a later step.
3. Next following the same process as we did in step 2, create a new file named sequans in the /etc/ppp/peers/ folder with the following contents:
# /etc/ppp/options # # Sequans Monarch Module PPP options file # # To quickly see what options are active in this file, use this command: # egrep -v '#|^ *$' /etc/ppp/options # tyname - Use this serial port to communicate with the Monarch. The string "/dev/" is prepended to ttyname to form the name of # the device to open. /dev/serial0 # speed - a decimal number is taken as the desired baud rate for the serial device. 115200 # Use hardware flow control (i.e. RTS/CTS) to control the flow of data # on the serial port. crtscts # Don't agree to authenticate using CHAP. -chap # Increase debugging level (same as -d). If this option is given, pppd # will log the contents of all control packets sent or received in a # readable form. The packets are logged through syslog with facility # daemon and level debug. This information can be directed to a file by # setting up /etc/syslog.conf appropriately (see syslog.conf(5)). (If # pppd is compiled with extra debugging enabled, it will log messages # using facility local2 instead of daemon). debug # Disable the defaultroute option. defaultroute # With the dump option, pppd will print out all the option values which # have been set. This option is like the dryrun option except that pppd # proceeds as normal rather than exiting. dump # Don't use the modem control lines, pppd will ignore the state of the CD (Carrier Detect) signal and will not change the state of the DTR local # pppd should create a UUCP-style lock file for the serial device to ensure exclusive access to the device. lock # Do not require the peer to authenticate itself. This option is privileged. noauth # Don't detach from the controlling terminal. Without this option nodetach # the peer will supply the local IP address during IPCP negotiation (unless it specified explicitly on the command line or in an options file) noipdefault # Ask the peer for up to 2 DNS server addresses. The addresses supplied by the peer (if any) are passed to the /etc/ppp/ip-up script in the environment # variables DNS1 and DNS2, and the environment variable USEPEERDNS will be set to 1. In addition, pppd will create an /etc/ppp/resolv.conf file containing # one or two nameserver lines with the address(es) supplied by the peer. usepeerdns # specify command for pppd to execute by using chat before starting # PPP negotiation. chat provides a way to send arbitrary strings to the # modem and respond to received characters. connect "/usr/sbin/chat -t6 -f /etc/chatscripts/connect" # after pppd has terminated the link, issue command to the modem to cause # it to hang up. disconnect "/usr/sbin/chat -t6 -f /etc/chatscripts/disconnect" # ---<End of File>---
This new sequans file specifies all of the options that will be pushed into the new PPP session once it is intitiated.
4.Next, I create a new file named connect in the /etc/chatscripts/ folder with the following contents, follow the same process for doing so as described in step 2 and 3.
# This is the chat script used to dial out to the Sequans Module # #ABORT "NO CARRIER" TIMEOUT 30 ABORT ERROR "" AT OK AT+CGDATA="PPP",3 CONNECT ""
This specifies the AT commands that are used to establish the network PPP connection.
5.Next create a new file named disconnect in the /etc/chatscripts/ folder. Follow the same process as described above for doing so.
# This is the chat script used to hang up the Sequans Module # "" "\d\d\d+++\c"
This specififes the string sent to the modem in order to disconnect the PPP connection
6. Last step is to edit the /etc/network/interfaces file and adding the following lines. You can do this using Vi or
# Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d auto ppp0
Connect to the Internet
1. Remeber, if you powered down the board, you will need to reconfigure the RTS and CTS gpio
a. RTS configure as an output with a value of 0
echo 17 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio17/direction echo 0 > /sys/class/gpio/gpio17/value
CTS configure as an input
echo 16 > /sys/class/gpio/export echo in > /sys/class/gpio/gpio16/direction
2. Now lets bring up the PPP. Run the following command
sudo ifup ppp0 &
With a bit of luck, the connection session will be negotiated successfully, an IP address assigned, and DNS servers identified:
3. Type in ifconfig and you can see the IP address associated with the Modem.
4. Congrats, you have successful brough up the PPP interface with the Monarch Go Modem. Lets now ping an interface to verify connectivity
ping -I ppp0 8.8.8.8
Now that networking capability is demonstrated, the next sections will focus upon getting an application up and running that relies upon the new ppp0 networking interface. In our instance we will enable an IoTConnect application
5. Now lets power down the raspberry pi as we move onto the next Demo. In terminal type
sudo shutdown -h now
IoTConnect Cloud Solution Demo
IoT Connect Account Setup
1. Sign up for Avnet IoT Connect by filling out the getting started section at the bottom this this webpage
IoT Connect Python SDK Install
The folks in the Avnet IoTConnect team pointed me to the easy to use IoTConnect SDK Python client for the device side programming. After configuring a few variables to match the IoTConnect account details I was assigned, I had some test data posting from my Ultra96-V2 board pretty quickly.
1. First download the IoT Connect SDK for Python from the IoT Connect website. Unzip the SDK onto the boot directory of your SD Card
2. Unzip the "iotconnect-sdk-pyth to the boot directory of your Raspberry Pi SD Card.
3. Eject the SD Card and plug it back into the Raspberry Pi, power up and login to the terminal
4.Go into the IoTConnect folder and use pip3 to install the iotconnect SDK
cd /boot/iotconnect-sdk-python-v2.0-1/iotconnect-sdk pip3 install iotconnect-sdk-2.0.tar.gz
Note - The pip3 install will take a couple minutes. The Python SDK is successfully installed.
Setup Device Dashboard in IoTConnect
1. Create a Template in the IoTConnect Dashboard. Devices -> Templates -> Create Template
2. Save Template after filling in information
3. Create Attributes Example and Save
4.Create Twin Property and Save
5. In the IotConnect Dashboard go Devices -> Devices -> Create Device
6. Make the Unique ID and Display name unique for to you. Select your entity and select the Basic_1 template. Select save
You have successfull setup your dashboard.
Run the IoTConnect Example
1. Return back to the "Connect to the Internet" Section we went through earlier and establish the PPP with the Monarch go.
2. Go into the sample directory and see what files are there.
cd ./sample/ ls
3. You will notice a example_py2.py example and example_py3.py example. The py2 is related to using python2, the py3 is related to using python3. Seeing as we used pip3 and not pip to install the IoTConnect python SDK, we will be using the python3 example.
4. We need to setup ppp0 as the default network run the following to determine the IP address of ppp0
netstat -rn
6. Now that we have determined the IP address, run the following substituting your own IP address
sudo route add default gw XXX.XXX.XX.X netstat -rn
7. Run the example_py3.py example using python 3
python3 ./example_py3.py
8. You will be promoted for your device serial number (Unique ID) along with your CPID
a. The device serial number is the Unique ID we gave it when we setup the dashboard. In this example mine is PiMonarch1234
b. CPID can be found by going Settings -> Company Profile -> CPID
9. After about 30-50 seconds the connection will be established and it will ask for a value to send up the the IoTconnect dashboard. Before we send data lets open the dashboard up
a. Go Devices -> Devices -> Unique ID
b.Select live data, here is where you can see all the published data.
10.Type in a value to be published, you shouls see some data published similiarly to this.
11. Now lets send data down from the cloud to the edge device. Open up twin properties at the top of the page, select the twin property we made earlier and enter a desired value to send down to the Raspberry Pi. Select Execute Twin Property.
Conclusion