Skip to content

Commit

Permalink
bring the updates
Browse files Browse the repository at this point in the history
Breaking change! The GPS is now expected to run at 115k baud.

Others:

    Minimum distance in meters between updates
    Automatic shutdown if battery voltage goes below certain value
  • Loading branch information
designer2k2 authored Mar 10, 2024
1 parent 318afd2 commit 4983af9
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 176 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/buildproject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:
python-version: '3.10'
- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Copy the config template
run: |
cp "./src/config.h.template" "./src/config.h"
- name: Build PlatformIO Project
run: pio run
2 changes: 1 addition & 1 deletion .github/workflows/spell_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:

# See: https://github.com/codespell-project/actions-codespell/blob/master/README.md
- name: Spell check
uses: codespell-project/actions-codespell@master
uses: codespell-project/actions-codespell@v2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ dkms.conf
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
src/config.h
67 changes: 0 additions & 67 deletions .travis.yml

This file was deleted.

6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Working in 2024 with TTN V3.
* T-Beam 1.0 in 868MHZ (yes that's an old one).
* Only tested with Platformio in VScode.
* GPS set to 115k baud (must be done with u-center or so).
* TX window, only send if moved at least a configurable distance.
* Auto power off if battery is below a configurable voltage.
* supports OLED display on the I²C interface on GPIO22 and GPI21. This repo contains a patched SSD1306 library from [smartnick](https://github.com/smartinick/Adafruit_SSD1306), enabling individual I²C pins and to set I²C Clock to 800kHz.

This is a simple sketch demonstrating the capability of the [TTGO T-Beam](https://www.aliexpress.com/store/product/TTGO-T-Beam-ESP32-433-868-915Mhz-WiFi-wireless-Bluetooth-Module-ESP-32-GPS-NEO-6M/2090076_32875743018.html) as a [TTN Mapper](https://ttnmapper.org/) Node on [The Things Network](https://www.thethingsnetwork.org/) LoraWAN.

Expand All @@ -29,7 +33,7 @@ The forked repo from hottimuc was converted to a PlatformIO project (currently f

## Instructions

Copy all from here locally, open it with PlatformIO, modify the config.h with your ABP credentials and upload.
Copy all from here locally, open it with PlatformIO, rename **config.h.template** to **config.h** and fill with your ABP credentials. Then upload it to the T-Beam.

On The Things Network side, the settings needed are available [here](https://www.thethingsnetwork.org/docs/applications/ttnmapper/).

Expand Down
52 changes: 26 additions & 26 deletions src/config.h → src/config.h.template
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
// Using ABP for now.
//#define OTAA

#ifndef LORA_TTNMAPPER_TBEAM_CONFIG_INCLUDED
#define LORA_TTNMAPPER_TBEAM_CONFIG_INCLUDED

#define CFG_eu868 1

#ifndef OTAA
// UPDATE WITH YOUR TTN KEYS AND ADDR.
// Setting for ABP
static PROGMEM u1_t NWKSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // LoRaWAN NwkSKey, network session key
static u1_t PROGMEM APPSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // LoRaWAN AppSKey, application session key
static const u4_t DEVADDR = 0x00000000; // LoRaWAN end-device address (DevAddr)
#else
// Settings from OTAA device (not used)
static const u1_t PROGMEM DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } ; // Device EUI, hex, lsb
static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // Application EUI, hex, lsb
static const u1_t PROGMEM APPKEY[16] = { 0x12, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01 }; // App Key, hex, msb

void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
#endif

#endif //LORA_TTNMAPPER_TBEAM_CONFIG_INCLUDED
// Using ABP for now.
//#define OTAA

#ifndef LORA_TTNMAPPER_TBEAM_CONFIG_INCLUDED
#define LORA_TTNMAPPER_TBEAM_CONFIG_INCLUDED

#define CFG_eu868 1

#ifndef OTAA
// UPDATE WITH YOUR TTN KEYS AND ADDR.
// Setting for ABP
static PROGMEM u1_t NWKSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // LoRaWAN NwkSKey, network session key
static u1_t PROGMEM APPSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // LoRaWAN AppSKey, application session key
static const u4_t DEVADDR = 0x00000000; // LoRaWAN end-device address (DevAddr)
#else
// Settings from OTAA device (not used)
static const u1_t PROGMEM DEVEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } ; // Device EUI, hex, lsb
static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // Application EUI, hex, lsb
static const u1_t PROGMEM APPKEY[16] = { 0x12, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45, 0x67, 0x89, 0x01 }; // App Key, hex, msb

void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}
void os_getDevKey (u1_t* buf) { memcpy_P(buf, APPKEY, 16);}
#endif

#endif //LORA_TTNMAPPER_TBEAM_CONFIG_INCLUDED
65 changes: 55 additions & 10 deletions src/fromV08.ino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"

#define MIN_DIST 20.0 // Minimum distance in meters from the last sent location before we send again.
#define STATIONARY_TX_INTERVAL (1 * 60) // Send one uplink at least once every N seconds

// Below BATTERY_LOW_VOLTAGE, power off until USB power allows charging.
// The PMIC also has a (safety) turn-off at 2.6v, much lower than this setting.
// We use a conservative cutoff here since the battery will last longer if it's not repeatedly run to minimum.
// A new-condition 18650 cell gives around 9Wh (Molicell) when discharged to the absolute lowest 2.5v
// 8110mWh to 3.3v
// 8875mWh to 3.1v
// 9210mWh to 2.5v
#define BATTERY_LOW_VOLTAGE 3.3

// T-Beam specific hardware
#define SELECT_BTN 38

Expand Down Expand Up @@ -44,6 +56,12 @@ uint16_t txBuffer2[5];
gps gps;
Preferences prefs;

float min_dist_moved = MIN_DIST;
double last_send_lat = 0; // Last known location
double last_send_lon = 0; //
double dist_moved = 0; // Distance in m from last uplink
unsigned long int last_send_ms = 0; // Time of last uplink

#ifndef OTAA
// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
Expand Down Expand Up @@ -76,18 +94,19 @@ void do_send(osjob_t* j) {
Serial.println(F("OP_TXRXPEND, not sending"));
LoraStatus = "OP_TXRXPEND, not sending";
} else {
if (gps.checkGpsFix())
//if (true)
{
if (gps.checkGpsFix() && ((dist_moved > min_dist_moved) || (millis() > (last_send_ms + STATIONARY_TX_INTERVAL * 1000)))) {
// Prepare upstream data transmission at the next possible time.
gps.buildPacket(txBuffer);
last_send_lat = gps.tGps.location.lat();
last_send_lon = gps.tGps.location.lng();
last_send_ms = millis();
LMIC_setTxData2(port, txBuffer, sizeof(txBuffer), 0);
Serial.println(F("Packet queued"));
axp.setChgLEDMode(ledMode);
LoraStatus = "Packet queued";
} else {
//try again in 3 seconds
os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(3), do_send);
//try again in 2 seconds
os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(2), do_send);
}
}
// Next TX is scheduled after TX_COMPLETE event.
Expand Down Expand Up @@ -214,7 +233,6 @@ void sf_select() {
}
if (selection == 2) // Unused
{

}
if (selection == 3) // Change Port
{
Expand Down Expand Up @@ -332,6 +350,13 @@ void onEvent(ev_t ev) {
}


// Power OFF -- does not return
void clean_shutdown(void) {
LMIC_shutdown(); // cleanly shutdown the radio
axp.setChgLEDMode(AXP20X_LED_OFF); // Surprisingly sticky if you don't set it
axp.shutdown(); // PMIC power off
}


void setup() {
Serial.begin(115200);
Expand All @@ -354,14 +379,15 @@ void setup() {
axp.adc1Enable(AXP202_VBUS_CUR_ADC1, true);

// activate power rails
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); // LORA radio
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS main power
axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); // LORA radio
axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS main power
axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON);
axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON);
axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON);

// enable only the short press IRQ
axp.enableIRQ(AXP202_PEK_SHORTPRESS_IRQ, true);
axp.enableIRQ(AXP202_PEK_LONGPRESS_IRQ, true);
axp.clearIRQ();

// read preferences
Expand Down Expand Up @@ -489,18 +515,35 @@ void loop() {
ledMode = AXP20X_LED_OFF;
}
}
if (axp.isPEKLongtPressIRQ()) {
// want to turn OFF
clean_shutdown();
}
axp.clearIRQ();
}

gps.encode();
sf_select();
os_runloop_once();

if (lastMillis + 1000 < millis()) {
lastMillis = millis();
VBAT = axp.getBattVoltage() / 1000;

os_runloop_once();
float charge_ma = axp.getBattChargeCurrent();

if (axp.isBatteryConnect() && VBAT < BATTERY_LOW_VOLTAGE && charge_ma < 99.0) {
Serial.println("Low Battery OFF");
clean_shutdown();
}


if (gps.checkGpsFix()) {
GPSonceFixed = true;

// distance from last transmitted location
dist_moved = gps.tGps.distanceBetween(last_send_lat, last_send_lon, gps.tGps.location.lat(), gps.tGps.location.lng());

noFix = false;
gps.gdisplay(txBuffer2);
float hdop = txBuffer2[4] / 10.0;
Expand All @@ -521,7 +564,7 @@ void loop() {
display.setCursor(0, 10);
display.print("Speed: " + String(txBuffer2[1]) + " km/h");
display.setCursor(0, 20);
display.print("Course: " + String(txBuffer2[2]) + (char)247);
display.print("Dist: " + String(dist_moved,0) + "m");
display.setCursor(0, 30);
display.print("Alt: " + String(txBuffer2[3]) + "m");
display.setCursor(0, 40);
Expand Down Expand Up @@ -577,6 +620,8 @@ void loop() {
} else {
display.print("v");
}
display.setCursor(0, 0);
display.print("SAT: " + String(gps.tGps.satellites.value()));
}
redraw = true;
}
Expand Down
Loading

0 comments on commit 4983af9

Please sign in to comment.