Intro

  • Flash Pi with Lite version

  • Place SSH file in root of SD card

# Mac/Linux create empty ssh file

touch /Volumes/boot/ssh
  • Place wpa_supplicant.conf in root of SD card

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
     ssid="[ENTER_YOUR_SSID_HERE]"
     psk="[ENTER_YOUR_PASSWORD_HERE]"
     key_mgmt=WPA-PSK
}
  • Boot Pi and locate it on the network

    • You can generally find Pi Zero's IP by looking in your router admin

  • SSH into Pi Zero and update/upgrade:

sudo apt update && sudo apt upgrade

Enable Serial Communication with GSM Hat

sudo raspi-config
  • Select Interfacing Options

  • Select Serial Port

  • Select No for login shell access over serial port

  • Select Yes for serial part hardware to be enabled

  • Exit raspi-config and reboot

Communication with GSM Hat

Let's confirm communication with the Waveshare GSM Hat. Place the hat on Pi Zero. Install the piccom library

Make sure to have a SIM card installed and activate. You can purchase from hologram.io

sudo apt install picocom

Let's test serial communication

picocom -b 9600 /dev/serial0

To end picocom session execute CTRL-A followed by CTRL-X

Issue the following AT commands to bring the module up on the network:

# Attach to GPRS
AT+CGATT=1

# Check the GPRS attachment (should be 1)
AT+CGATT?

Using the Hologram IoT network let's set the APN:

# Set Hologram APN
AT+CSTT="hologram"

Establish the wireless connection:

# Establish the wireless connection
AT+CIICR

The follow command allows you to check your network IP:

AT+CIFSR

Sending SMS with AT Commands

# Set to SMS mode
AT+CMGF=1

# Specify the recipient
AT+CMGS="+1222333444"

Now type in your message and to end the message and send use CTRL-Z and press enter. This will terminate and send the message.

Python and DroneKit

Pi Zero should already have Python installed. You can verify this by issuing the following command:

python --version

In my case I have Python 2.7.16, which is sufficient to run DroneKit. Before installing Python we need to install a few dependencies:

sudo apt install python-pip python-dev python-lxml libxml2-dev libxslt-dev

Now you should be able to install DroneKit:

sudo pip install dronekit

Send SMS with Python

The script below will send an SMS message the to designated recipient. Be sure to change the phone number in the script. To communicate with the GSM over serial be sure to install the serial port module.

sudo pip install pyserial
# at.py
# A basic script to send SMS with Waveshare GSM Hat

import serial

conn = serial.Serial('/dev/serial0', baudrate=9600, timeout=1.0)

conn.write('AT+CMGF=1\r\n')
result = conn.read(100)
print(result)

# Change the line below to your phone number
conn.write('AT+CMGS="+11234567890"\r\n')
result = conn.read(100)
print(result)

conn.write('Hello from Pi Zero')
result = conn.read(100)
print(result)

conn.write('\x1A\r\n')
result = conn.read(100)
print(result)

DroneKit Scripts

The following script is for testing basic communication with your autopilot hardware running PX4. In my case I'm using Pixfalcon with Pi Zero connected to the micro USB port.

# dronekit-gps.py

from __future__ import print_function
from dronekit import connect, VehicleMode
import time

# Connect to Pixfalcon's serial port
vehicle = connect('/dev/ttyACM0', wait_ready=True, baud=9600)

print(" Autopilot Firmware version: %s" % vehicle.version)

# Loop continuously and print the GPS location every second
while True:
  print("Location: ", vehicle.location.global_frame)
  print("Attitude: ", vehicle.attitude)
  time.sleep(1)

The following script combines the AT SMS commands with GPS from DroneKit to send a Google Maps link to the designated phone number.

# dronekit_gps_to_sms.py

from dronekit import connect, VehicleMode
import time
import serial

def send(lat, lon):
    conn = serial.Serial('/dev/serial0', baudrate=9600, timeout=1.0)

    conn.write('AT+CMGF=1\r\n')
    result = conn.read(100)
    print(result)

    conn.write('AT+CMGS="+11234567890"\r\n')
    result = conn.read(100)
    print(result)

    conn.write('https://www.google.com/maps/place/' + str(lat) + ',' + str(lon))
    result = conn.read(100)
    print(result)

    conn.write('\x1A\r\n')
    result = conn.read(100)
    print(result)

vehicle = connect('/dev/ttyACM0', wait_ready=True, baud=9600)

# Send an SMS message with GPS location every 10 seconds
while True:
    print("Location: ", vehicle.location.global_frame)
    send(vehicle.location.global_frame.lat, vehicle.location.global_frame.lon)
    time.sleep(10)

Work in progress below to stream UDP to QGC....

qgc.py

from __future__ import print_function
from dronekit import connect, VehicleMode
from dronekit.mavlink import MAVConnection
vehicle = connect('/dev/ttyACM0', wait_ready=True, baud=9600)

udp_conn = MAVConnection('udpin:0.0.0.0:15667', source_system=1)
vehicle._handler.pipe(udp_conn)
udp_conn.master.mav.srcComponent = 1  # needed to make QGroundControl work!
udp_conn.start()

Last updated

Was this helpful?