Skip to content

Commit

Permalink
Merge pull request #14 from LeeLeahy2/9-6-fix
Browse files Browse the repository at this point in the history
Fix example 9-6
  • Loading branch information
nseidle authored Sep 27, 2024
2 parents 9e1f016 + 7cd6f77 commit e2ac13d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void setup()
Serial.println("SparkFun EVK Example");

// Listen for modem events
Serial.printf("Registering callback handler: %p\r\n", (void *)networkOnEvent);
Network.onEvent(networkOnEvent);

// Set LARA_PWR low
Expand Down
31 changes: 16 additions & 15 deletions Example_Sketches/9_6_Network_Failover/Cellular.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void cellularAttached(uint8_t priority, uintptr_t parameter, bool debug)
{
// Attached to a mobile network, continue
// Display the network information
Serial.printf("Cellular attached to %s\r\n", CELLULAR.operatorName());
Serial.printf("Cellular attached to %s\r\n", CELLULAR.operatorName().c_str());
if (debug)
{
Serial.print(" State: ");
Expand Down Expand Up @@ -65,7 +65,7 @@ void cellularAttached(uint8_t priority, uintptr_t parameter, bool debug)
}

//----------------------------------------
// Handle the cellular evnets
// Handle the cellular events
void cellularEvent(arduino_event_id_t event)
{
IPAddress ipAddress;
Expand Down Expand Up @@ -112,7 +112,7 @@ void cellularEvent(arduino_event_id_t event)
module = CELLULAR.moduleName();
Serial.printf("Cellular (%s %s) Started\r\n", manufacturer.c_str(), module.c_str());
if (NETWORK_DEBUG_SEQUENCE)
Serial.printf(" IMEI: %s\r\n", CELLULAR.IMEI());
Serial.printf(" IMEI: %s\r\n", CELLULAR.IMEI().c_str());
break;

case ARDUINO_EVENT_PPP_STOP:
Expand All @@ -122,37 +122,38 @@ void cellularEvent(arduino_event_id_t event)
}

//----------------------------------------
void cellularSetup(uint8_t priority, uintptr_t parameter, bool debug)
void cellularStart(uint8_t priority, uintptr_t parameter, bool debug)
{
// Validate the priority
networkPriorityValidation(priority);

// Now let the PPP turn the modem back on again if needed - with a 200ms reset
// If the modem is on, this is too short to turn it off again
Serial.println("Setting up the cellular modem.");

// Configure the cellular modem
CELLULAR.setApn(CELLULAR_MODEM_APN);
CELLULAR.setPin(CELLULAR_MODEM_PIN);
CELLULAR.setResetPin(CELLULAR_RST, CELLULAR_MODEM_RST_LOW); // v3.0.2 allows you to set the reset delay, but we don't need it
CELLULAR.setPins(CELLULAR_TX, CELLULAR_RX, CELLULAR_RTS, CELLULAR_CTS, CELLULAR_MODEM_FC);

// Now let the PPP turn the modem back on again if needed - with a 200ms reset
// If the modem is on, this is too short to turn it off again
Serial.println("Starting the modem. It might take a while!");

// Starting the cellular modem
CELLULAR.begin(CELLULAR_MODEM_MODEL);

// Get the next sequence entry
networkSequenceNextEntry(priority, debug);
}

//----------------------------------------
void cellularStart(uint8_t priority, uintptr_t parameter, bool debug)
void cellularStop(uint8_t priority, uintptr_t parameter, bool debug)
{
// Validate the priority
networkPriorityValidation(priority);

// Now let the PPP turn the modem back on again if needed - with a 200ms reset
// If the modem is on, this is too short to turn it off again
Serial.println("Starting the modem. It might take a while!");

// Starting the cellular modem
CELLULAR.begin(CELLULAR_MODEM_MODEL);
// Stopping the cellular modem
Serial.println("Stopping the modem!");
CELLULAR.mode(ESP_MODEM_MODE_COMMAND);
CELLULAR.end();

// Get the next sequence entry
networkSequenceNextEntry(priority, debug);
Expand Down
2 changes: 1 addition & 1 deletion Example_Sketches/9_6_Network_Failover/LARA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ void laraPowerLow(uint8_t priority, uintptr_t parameter, bool debug)
NETWORK_POLL_SEQUENCE laraBootSequence[] =
{ // State Parameter Description
{laraSetPins, LARA_SETTLE_TIME, "Initialize the pins"},
{cellularSetup, 0, "Initialize the cellular layer"},
{networkDelay, (uintptr_t)&laraTimer, "Delay for initializtion"},

// Power on LARA, may already be on during software reload
Expand Down Expand Up @@ -151,6 +150,7 @@ NETWORK_POLL_SEQUENCE laraOnSequence[] =
// (Remember that LARA_PWR is inverted by the RTK EVK level-shifter)
NETWORK_POLL_SEQUENCE laraOffSequence[] =
{ // State Parameter Description
{cellularStop, 0, "Stop the cellular modem"},
{laraPowerLow, LARA_OFF_TIME, "Notify LARA of power state change"},
{networkDelay, (uintptr_t)&laraTimer, "Tell LARA to power off"},
{laraPowerHigh, LARA_SETTLE_TIME, "Finish power off sequence"},
Expand Down
57 changes: 33 additions & 24 deletions Example_Sketches/9_6_Network_Failover/Network.ino
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,17 @@ void networkSequenceBoot(uint8_t priority)

// Display the description
sequence = networkPriorityTable[priority].boot;
description = sequence->description;
if (debug && description)
Serial.printf("%s: %s\r\n", networkGetName(priority), description);

// Start the boot sequence
networkSequence[priority] = sequence;
networkSeqStarting &= ~bitMask;
networkSeqStopping &= ~bitMask;
if (sequence)
{
description = sequence->description;
if (debug && description)
Serial.printf("%s: %s\r\n", networkGetName(priority), description);

// Start the boot sequence
networkSequence[priority] = sequence;
networkSeqStarting &= ~bitMask;
networkSeqStopping &= ~bitMask;
}
}

//----------------------------------------
Expand Down Expand Up @@ -492,14 +495,17 @@ void networkSequenceStart(uint8_t priority, bool debug)

// Display the description
sequence = networkPriorityTable[priority].start;
description = sequence->description;
if (debug && description)
Serial.printf("%s: %s\r\n", networkGetName(priority), description);

// Start the sequence
networkSequence[priority] = sequence;
networkSeqStarting |= bitMask;
networkStarted |= bitMask;
if (sequence)
{
description = sequence->description;
if (debug && description)
Serial.printf("%s: %s\r\n", networkGetName(priority), description);

// Start the sequence
networkSequence[priority] = sequence;
networkSeqStarting |= bitMask;
networkStarted |= bitMask;
}
}
}

Expand Down Expand Up @@ -565,14 +571,17 @@ void networkSequenceStop(uint8_t priority, bool debug)

// Display the description
sequence = networkPriorityTable[priority].stop;
description = sequence->description;
if (debug && description)
Serial.printf("%s: %s\r\n", networkGetName(priority), description);

// Start the sequence
networkSeqStopping |= bitMask;
networkStarted &= ~bitMask;
networkSequence[priority] = sequence;
if (sequence)
{
description = sequence->description;
if (debug && description)
Serial.printf("%s: %s\r\n", networkGetName(priority), description);

// Start the sequence
networkSeqStopping |= bitMask;
networkStarted &= ~bitMask;
networkSequence[priority] = sequence;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions Example_Sketches/9_6_Network_Failover/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ example: build/esp32.esp32.esp32/$(EXAMPLE_SKETCH).ino.bin

DEBUG_LEVEL=none
#DEBUG_LEVEL=debug
#DEBUG_LEVEL=verbose

build/esp32.esp32.esp32/$(EXAMPLE_SKETCH).ino.bin: $(EXAMPLE_SKETCH).ino *.ino *.h makefile
$(CLEAR)
Expand Down

0 comments on commit e2ac13d

Please sign in to comment.