LoRa gateway to Habitat
Part of the LoRa Balloon Tracking System. Receives balloon telemetry and uploads to Sondehub and/or MQTT.
ALL HABHUB SUPPORT HAS BEEN REMOVED since that server has been decommissioned
If you are updating from an old version, please see the MQTT section below to install a library that you will need to build the latest version.
Runs on a Raspberry Pi with 1 or 2 RFM98HW modules attached to the SPI port. Also works with other compatible HopeRF and Semtec LoRa devices.
If you're making your own board for the Pi, connect the LoRa module(s) like so:
LORA PI
---- --
3.3V 3.3V Power
GND Ground
MOSI MOSI (pin 19)
MISO MISO (pin 21)
NSS CE0 (pin 24) (CE1 (pin 26) for 2nd module)
SCK SLCK
DIO0 Wiring Pi 31 (Pin 28) (Wiring Pi 6 (pin 22) for 2nd module)
DIO5 Wiring Pi 26 (Pin 32) (Wiring Pi 5 (pin 18) for 2nd module). Set to -1 if not connected.Enable SPI in raspi-config
sudo apt-get install git libcurl4-openssl-dev libncurses5-dev libssl-devRaspberry Pi OS no longer includes SSDV, so you must install SSDV from source as follows:
cd ~
git clone https://github.com/fsphil/ssdv.git
cd ssdv
make
sudo make installRaspberry Pi OS no longer includes WiringPi, so you must install Wiring Pi from source as follows:
cd ~
git clone https://github.com/WiringPi/WiringPi.git
cd WiringPi
./buildMQTT support was added recently, and needs the following library installed::
cd ~
mkdir MQTTClients
cd MQTTClients
git clone https://github.com/janderholm/paho.mqtt.c.git
cd paho.mqtt.c
make
sudo make installcd ~
git clone https://github.com/PiInTheSky/lora-gateway.git
cd lora-gateway
make
cp gateway-sample.txt gateway.txtThe configuration is in the file gateway.txt. Example:
tracker=M0RPI
EnableSondehub=Y
EnableSSDV=Y
LogTelemetry=Y
LogPackets=Y
CallingTimeout=60
JPGFolder=ssdv
CallingTimeout=60
ServerPort=6004
Latitude=51.95023
Longitude=-2.5445
Radio=LoRa RFM98W
Antenna=868MHz Yagi
frequency_0=434.347
mode_0=1
DIO0_0=31
DIO5_0=26
AFC_0=N
frequency_1=434.475
mode_1=5
DIO0_1=6
DIO5_1=5
AFC_1=YThe global options are:
tracker=. This is whatever callsign you want to appear as on the tracking map and/or SSDV page.
EnableHabitat=. Enables uploading of telemetry packets to Habitat.
EnableSondehub=. Enables uploading of telemetry packets to the amateur Sondehub system.
EnableSSDV=. Enables uploading of SSDV image packets to the SSDV server.
EnableHABLink=. Enables uploading of telemetry packets to the hab.link server.
JPGFolder=. Tells the gateway where to save local JPEG files built from incoming SSDV packets.
LogTelemetry=. Enables logging of telemetry packets (ASCII only at present) to telemetry.txt.
LogPackets=. Enables logging of packet information (SNR, RSSI, length, type) to packets.txt.
SMSFolder=. Tells the gateway to check for incoming SMS messages or tweets that should be sent to the tracker via the uplink.
CallingTimeout=. Sets a timeout for returning to calling mode after a period with no received packets.
ServerPort=. Opens a server socket which can have 1 client connected. Sends JSON telemetry and status information to that client.
HABPort=. Opens a server socket which can have 1 client connected. Port is a raw data stream between gateway and HAB (e.g. for Telnet-like communications). Note: The corresponding functionality at the tracker end has not been published.
DataPort=. Opens a server socket which can have 1 client connected. Sends raw telemetry (i.e. $$payload,....) to that client.
HABTimeout=. Timeout in case of no response from HAB to raw data uplink.
HABChannel=. Specifies LoRa channel (0 or 1) used for telnet-style communications.
Latitude=
Longitude=. These let you tell the gateway your position, for uploading to habitat, so your listener icon appears on the map in the correct position.
Radio=. Lets you specify your radio/board make/model or type. This appears on the map if your listener icon is clicked on.
Antenna=. Lets you specify your antenna make/model or type. This appears on the map if your listener icon is clicked on.
NetworkLED=
InternetLED=
ActivityLED_0=
ActivityLED_1=. These are used for LED status indicators. Useful for packaged gateways that don't have a monitor attached.and the channel-specific options are:
frequency_=. This sets the frequency for LoRa module (0 for first, 1 for second). e.g. frequency_0=434.450
PPM_==. Enables or disables automatic frequency control (retunes by the frequency error of last received packet).
mode_=. Sets the "mode" for the selected LoRa module. This offers a simple way of setting the various
LoRa parameters (SF etc.) in one go. The modes are:
0 = (normal for telemetry) Explicit mode, Error coding 4:8, Bandwidth 20.8kHz, SF 11, Low data rate optimize on
1 = (normal for SSDV) Implicit mode, Error coding 4:5, Bandwidth 20.8kHz, SF 6, Low data rate optimize off
2 = (normal for repeater) Explicit mode, Error coding 4:8, Bandwidth 62.5kHz, SF 8, Low data rate optimize off
3 = (normal for fast SSDV) Explicit mode, Error coding 4:6, Bandwidth 250kHz, SF 7, Low data rate optimize off
4 = Test mode not for normal use.
5 = (normal for calling mode) Explicit mode, Error coding 4:8, Bandwidth 41.7kHz, SF 11, Low data rate optimize off
SF_= e.g. SF_0=7
Bandwidth_=. e.g. Bandwidth_0=41K7. Options are 7K8, 10K4, 15K6, 20K8, 31K25, 41K7, 62K5, 125K, 250K, 500K
Implicit_=. e.g. Implicit_0=Y
Coding_=. e.g. Coding_0=5 (4:5)
lowopt_=. Enables or disables low data rate optimization.
power_=. This is the power setting used for uplinks. Refer to the LoRa manual for details on setting this. ** Only set values that are legal in your location (for EU see IR2030) **
UplinkTime_0=. When to send any uplink messages, measured as seconds into each cycle.
UplinkCycle_0=. Cycle time for uplinks. First cycle starts at 00:00:00. So for uplink time=2 and cycle=30, any transmissions will start at 2 and 32 seconds after each minute.Lines are commented out with "#" at the start.
If the frequency_n line is commented out, then that channel is disabled.
The program now performs some checks to determine if each selected LoRa module is present or not. If you see a message "RFM not found on Channel" then check the SPI settings/wiring for that channel. If you see "DIO5 pin is misconfigured on Channel" then check the DIO5 setting/wiring. There is no current check for DIO0; any problems with that pin will result in packets not being received.
The gateway can uplink messages to the tracker. Currently this is restricted to time-based uplink slots using "UplinkTime" and "UplinkCycle".
The code uses Linux system time, so the gateway should ideally be using a GPS receiver the GPSD daemon. NTP may prove sufficient however.
For uplinks to work, both UplinkTime and UplinkCycle have to be set for the appropriate channel.
There are currently two types of uplink supported:
- Uplink of messages from the "SMSFolder" folder. For this to work, "SMSFolder" has to be defined and present. The gateway will then check for "*.sms" files in that folder.
- Uplink of SSD packet re-send requests. The gateway looks for an "uplink.txt" file in the gateway folder. The file is created by an external Python script (supplied) which interrogates the SSDV server.It is possible for trackers to send out messages on a special "calling channel" as well as telemetry on their main frequency. The calling channel messages state the main frequency and LoRa modes.
This allows for gateways tp be normally left on the calling channel, so they then switch to each tracker as it comes within range.
There's nothing special about "calling mode" except that after a period (CallingTimeout seconds) of time without packets, the gateway returns to its default settings.
To enable calling mode, set the LoRa mode to 5, and the frequency to 433.650MHz.
To send telemetry to an MQTT broker, edit the MQTT settings in gateway.txt
e.g.:
# MQTT Config
EnableMQTT=Y
MQTTHost=mqtt_host
MQTTPort=1883
MQTTUser=mqtt_user
MQTTPass=mqtt_password
MQTTClient=mqtt_client_name
MQTTTopic=topic_nameThe display has a title bar at the top, scrolling log at the bottom, and 2 channel panels in the middle. Each panel shows something like:
Channel 0 869.8500MHz
Explicit, 250k, SF7, EC4:6
Telemetry 74 bytes
51.95028, -2.54443, 00138
Habitat SSDV 0000
0s since last packet
Telem Packets = 37
Image Packets = 0
Bad CRC = 0 Bad Type = 0
Packet SNR = 10, RSSI = -67
Freq. Error = 1.0kHz
Current RSSI = -64The "Habitat" text appears during uploads to habitat. Normally it will flash up then disappear quickly; if it stays on (not flickering) then the upload is slow.
The "SSDV 0000" text shows the current state of the SSDV upload buffers. There are 4 upload threads and each can handle up to 16 (0-9-A-F) packets in its queue. Normally, even with fast SSDV, uplinks should happen quickly enough for there to be no more than 1 or 2 active threads each with 1 packet being uploaded.
The following key presses are available. Where appropriate unshifted keys affect Channel 0 and shifted keys affect Channel 1. Many thanks to David Brooke for coding this feature and the AFC.
q quit
a increase frequency by 100kHz
z decrease frequency by 100kHz
s increase frequency by 10kHz
x decrease frequency by 10kHz
d increase frequency by 1kHz
c decrease frequency by 1kHz
f toggle AFCUse callsign for MQTT client IDFully handle all documented Sondehub responses - see https://github.com/projecthorus/sondehub-infra/wiki/API-(Beta)#notes-on-api-response-codesClear InUse flag in SH upload so new telemetry is only uploaded onceLimit to 5 retries on SH uploadUKHAS Telemetry is CRC16 checked before being used/uploaded, in addition to the existing LoRa CRC check
Separation of new incoming telemetry and that already being uploaded to Sondehub
Added parsing check on UKHAS telemetry before uploading to SondehubSondehub upload: For errors, log return code, return text and uploaded JSON to errors.txtRemoved all HABHUB SupportSondehub upload: Interpret battery voltage as V/mV automatiically
Sondehub upload: Send battery voltage in VSondehub datetime field now contains payload timestamp plus current UTC date, corrected if necessary for UTC being the day after the telemetry was created (i.e. telemetry just before midnight UTC received just after midnight)Include UKHAS sentence as "raw" value sent to sondehub/amateur
Remove any "/" character from listener callsign sent to sondehub/amateurScans telemetry for a fieldlist field. This is metadata defining the sequence of fields in the telemetry string
If found, then this field is used to extract fields such as sats, pred_lat etc., and send them to Sondehub/amateurFixed code that uploads to Sondehub so that a zero altitude doesn't result in a 400 response from the server
Any 400 responses are now logged to errors.txt along with the JSON that triggered them
A 400 response is no longer retriedOnly upload to Sondehub if telemetry has non-zero latitude or longitudeAdded support for uploadiNo open issues yet, or sync has not completed.