Commit da1be5d7 authored by Jan Grewe's avatar Jan Grewe
Browse files

more cleanup

LoRa retry causes "CORRUPT HEAP"
parent 0fb0ede2
#define SLEEP_SECONDS 900 // 15 minutes
#define GPS_INT_SECONDS 1
#define GPS_WAIT_SECONDS 120
#define LORA_RETRY 3
#define TTN_DEVEUI { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; // LSB
#define TTN_APPEUI { 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0xD5, 0xB3, 0x70 }; // LSB
......
......@@ -2,7 +2,6 @@
void powerLed(axp_chgled_mode_t);
float powerGetBattVoltage();
void powerSetOutput(uint8_t channel, bool enabled);
void powerStatus();
void powerSetup();
void powerSleep();
......
......@@ -20,7 +20,7 @@ build_flags =
-D ARDUINO_LMIC_CFG_NETWORK_TTN
-D CFG_sx1276_radio
-D CFG_eu868
-D LMIC_DEBUG_LEVEL=0
-D LMIC_DEBUG_LEVEL=2
lib_deps =
AXP202X_Library@1.1.2
TinyGPSPlus@1.0.2
......
......@@ -4,7 +4,7 @@
#include <TinyGPS++.h>
HardwareSerial GPS(1);
TinyGPSPlus gps;
extern TinyGPSPlus gps;
extern int state;
unsigned long gpsTimer;
unsigned long gpsCount;
......@@ -29,6 +29,7 @@ void gpsStatus()
Serial.printf("Time : %02d:%02d:%02d\n", gps.time.hour(), gps.time.minute(), gps.time.second());
Serial.printf("Speed : %g\n", gps.speed.kmph());
Serial.println("#########################\n");
gpsCount = 0;
}
void gpsSetup()
......
......@@ -7,6 +7,7 @@
#include <CayenneLPP.h>
extern int state;
int retry;
class cLoRaWAN : public Arduino_LoRaWAN_ttn
{
......@@ -105,6 +106,7 @@ void onEvent(ev_t ev)
break;
case EV_JOINING:
Serial.println(F("EV_JOINING"));
retry = 0;
break;
case EV_JOINED:
Serial.println(F("EV_JOINED"));
......@@ -159,8 +161,20 @@ void onEvent(ev_t ev)
break;
case EV_JOIN_TXCOMPLETE:
Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
// restart sending
state = STATE_READY;
if (retry < LORA_RETRY)
{
//Serial.printf("\nLoRa Join failed, %d retries left.\n\n", LORA_RETRY - retry);
// TODO: this will cause "CORRUPT HEAP: Bad head at / assertion "head != NULL" failed / abort() was called"
//state = STATE_INIT;
Serial.println("\nLoRa Join failed.");
state = STATE_DONE;
}
else
{
Serial.println("\nLoRa Join failed, no retries left.");
state = STATE_DONE;
}
break;
default:
Serial.println(F("Unknown event " + (unsigned)ev));
......
......@@ -8,11 +8,12 @@
int state;
CayenneLPP payload(55);
TinyGPSPlus gps;
void createPayload()
{
payload.reset();
TinyGPSPlus gps = getGps();
gps = getGps();
payload.addGPS(1, gps.location.lat(), gps.location.lng(), gps.altitude.meters());
payload.addAnalogInput(2, powerGetBattVoltage() / 1000);
}
......
......@@ -15,11 +15,6 @@ float powerGetBattVoltage()
return axp.getBattVoltage();
}
void powerSetOutput(uint8_t channel, bool enabled)
{
axp.setPowerOutPut(channel, enabled);
}
void powerStatus()
{
Serial.println("\n########## Power ##########");
......@@ -78,9 +73,9 @@ void powerSleep()
{
Serial.printf("\nSystem has been up for %llu seconds.\n", esp_timer_get_time()/1000000);
Serial.printf("Going to sleep for %d seconds.\n", SLEEP_SECONDS);
powerSetOutput(AXP192_LDO2, AXP202_OFF); // LORA : off
powerSetOutput(AXP192_LDO3, AXP202_OFF); // GPS : off
powerLed(AXP20X_LED_OFF);
axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF); // LORA : off
axp.setPowerOutPut(AXP192_LDO3, AXP202_OFF); // GPS : off
axp.setChgLEDMode(AXP20X_LED_OFF);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_38, LOW); // wake up with "user" button (middle)
esp_sleep_enable_timer_wakeup(1000000 * SLEEP_SECONDS);
Serial.println("\n### END ###");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment