Skip to content

Commit

Permalink
Fix wifi connection, remove all espressif light sleep
Browse files Browse the repository at this point in the history
Signed-off-by: Sara Damiano <[email protected]>
  • Loading branch information
SRGDamia1 committed Jun 21, 2022
1 parent cc9a66e commit 194d2f9
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 269 deletions.
6 changes: 2 additions & 4 deletions docs/Modem-Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ If you are having trouble, please see the pages for the specific modems and the
| Digi XBee3 LTE Cat 1 AT&T (Telit LE866A1-NA) | DigiXBeeCellularTransparent |
| Digi XBee S6B WiFi | DigiXBeeWifi |
| Espressif ESP8266 | EspressifESP8266 |
| Espressif ESP32 | EspressifESP8266 |
| Espressif ESP32 | EspressifESP32 |

This comment has been minimized.

Copy link
@neilh10

neilh10 Nov 10, 2022

Contributor

I'm just wondering, when a new or even current module is added, could there be a column where it's noted when it works. Unfortunately testing some thing works is a major activity, and I don't believe it is caught anywhere. Adding this module has broken the Digi WiFI #347

| Quectel BG96 | QuectelBG96 |
| Mikroe LTE IOT 2 Click (_BG96_| QuectelBG96 |
| Dragino NB IOT Bee (_BG96_| QuectelBG96 |
Expand Down Expand Up @@ -139,7 +139,7 @@ Here are the pin numbers to use for modules that can be attached directly to an
| Digi XBee/XBee3, all variants (direct connection)¹ | -1 | 19² | -1 | 23 |
| Digi XBee/XBee3, all variants (with LTE adapter<sup>8</sup>) | -1<sup>3</sup> | 19<sup>4</sup> | 20 | 23 |
| Itead Wee (ESP8266)<sup>8</sup> | -1 | -1 | -1<sup>5</sup> | -1 |
| DFRobot WiFi Bee (ESP8266) | -1 | -1 | -1 | 19<sup>6</sup> |
| DFRobot WiFi Bee (ESP8266) | -1 | -1 | -1 | N/A |
| Dragino NB IOT Bee (BG96) | -1 | -1 | -1<sup>7</sup> | -1<sup>7</sup> |
| Sodaq GPRSBee R4 (SIM900) | -1 | 19 | -1 | 23 |
| Sodaq GPRSBee R6 or R7 (SIM800H) | 23 | 19 | N/A | N/A |
Expand All @@ -163,8 +163,6 @@ You should set the argument `useCTSforStatus` to `false` in the bee constructor
<sup>5</sup> I *strongly* recommend running a new wire along the back of the Mayfly to connect pin 5 of the XBee socket to pin A4.
This will enable you to use A4 as the reset pin which allows you to use deep sleep.

<sup>6</sup> Use 13 as the `espSleepRqPin` for light sleep.

<sup>7</sup> I *strongly* recommend running two new wires along the back of the Mayfly to connect pin 5 of the XBee socket to pin A4 and pin 18 of the XBee socket to A3.
This will enable you to use A4 as the reset pin and A3 as the sleep request pin.
With those connections made, the Dragino BG96 becomes the _**only**_ LTE module that can be run using only the 500mA regulator on the Mayfly (ie, without a separate battery connection for the modem).
Expand Down
13 changes: 6 additions & 7 deletions examples/DRWI_Mayfly1_WiFi/DRWI_Mayfly1_WiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,18 @@ const int32_t modemBaud = 115200; // Communication speed of the modem
// NOTE: Use -1 for pins that do not apply
// Example pins here are for a EnviroDIY ESP32 Bluetooth/Wifi Bee with
// Mayfly 1.1
const int8_t modemVccPin = 18; // MCU pin controlling modem power
const int8_t modemStatusPin = -1; // MCU pin used to read modem status
const int8_t modemResetPin = A5; // MCU pin connected to modem reset pin
const int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem
// status
const int8_t modemVccPin = 18; // MCU pin controlling modem power
const int8_t modemResetPin = A5; // MCU pin connected to modem reset pin
const int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem
// status

// Network connection information
const char* wifiId = "xxxxx"; // WiFi access point name
const char* wifiPwd = "xxxxx"; // WiFi password (WPA2)

// Create the modem object
EspressifESP32 modemESP(&modemSerial, modemVccPin, modemStatusPin,
modemResetPin, wifiId, wifiPwd);
EspressifESP32 modemESP(&modemSerial, modemVccPin, modemResetPin, wifiId,
wifiPwd);
// Create an extra reference to the modem by a generic name
EspressifESP32 modem = modemESP;
/** End [espressif_esp32] */
Expand Down
18 changes: 4 additions & 14 deletions examples/logging_to_ThingSpeak/logging_to_ThingSpeak.ino
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,18 @@ const int32_t modemBaud = 115200; // Communication speed of the modem

// Modem Pins - Describe the physical pin connection of your modem to your board
// NOTE: Use -1 for pins that do not apply
const int8_t modemVccPin = -2; // MCU pin controlling modem power
const int8_t modemStatusPin = 19; // MCU pin used to read modem status
const int8_t modemResetPin = 20; // MCU pin connected to modem reset pin
const int8_t modemSleepRqPin = 23; // MCU pin for modem sleep/wake request
const int8_t modemVccPin = -2; // MCU pin controlling modem power
const int8_t modemResetPin = 20; // MCU pin connected to modem reset pin
const int8_t modemLEDPin =
redLED; // MCU pin connected an LED to show modem status

// Pins for light sleep on the ESP8266. For power savings, I recommend NOT using
// these if it's possible to use deep sleep.
const int8_t espSleepRqPin = -1; // GPIO# ON THE ESP8266 to assign for light
// sleep request
const int8_t espStatusPin = -1; // GPIO# ON THE ESP8266 to assign for light
// sleep status

// Network connection information
const char* wifiId = "xxxxx"; // The WiFi access point
const char* wifiPwd = "xxxxx"; // The password for connecting to WiFi

// Create the loggerModem object
EspressifESP8266 modemESP(&modemSerial, modemVccPin, modemStatusPin,
modemResetPin, modemSleepRqPin, wifiId, wifiPwd,
espSleepRqPin, espStatusPin);
EspressifESP8266 modemESP(&modemSerial, modemVccPin, modemResetPin, wifiId,
wifiPwd);
// Create an extra reference to the modem by a generic name
EspressifESP8266 modem = modemESP;
/** End [espressif_esp8266] */
Expand Down
2 changes: 0 additions & 2 deletions examples/menu_a_la_carte/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,7 @@ This code is for the Espressif ESP8266 or ESP32 operating with "AT" firmware.
To create a EspressifESP8266 object we need to know
- the serial object name,
- the MCU pin controlling modem power,
- the light sleep status pin (on both ESP and MCU),
- the reset pin (MCU pin connected to the ESP's `RSTB/DIO16`),
- the light sleep wake pin (on both the ESP and the MCU),
- the wifi access point name,
- and the wifi WPA2 password.

Expand Down
23 changes: 6 additions & 17 deletions examples/menu_a_la_carte/menu_a_la_carte.ino
Original file line number Diff line number Diff line change
Expand Up @@ -442,29 +442,18 @@ const int32_t modemBaud = 115200; // Communication speed of the modem
// NOTE: Use -1 for pins that do not apply
// Example pins here are for a EnviroDIY ESP32 Bluetooth/Wifi Bee with
// Mayfly 1.1
const int8_t modemVccPin = 18; // MCU pin controlling modem power
const int8_t modemStatusPin = -1; // MCU pin used to read modem status
const int8_t modemResetPin = A5; // MCU pin connected to modem reset pin
const int8_t modemSleepRqPin = 19; // MCU pin for wake from light sleep
const int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem
// status
// Pins for light sleep on the ESP8266. For power savings, I recommend
// NOT using these if it's possible to use deep sleep.
const int8_t espSleepRqPin = 13; // GPIO# ON THE ESP8266 to assign for light
// sleep request
const int8_t espStatusPin = -1; // GPIO# ON THE ESP8266 to assign for light
// sleep status
const int8_t modemVccPin = 18; // MCU pin controlling modem power
const int8_t modemResetPin = A5; // MCU pin connected to modem reset pin
const int8_t modemLEDPin = redLED; // MCU pin connected an LED to show modem
// status

// Network connection information
const char* wifiId = "xxxxx"; // WiFi access point name
const char* wifiPwd = "xxxxx"; // WiFi password (WPA2)

// Create the modem object
EspressifESP8266 modemESP(&modemSerial, modemVccPin, modemStatusPin,
modemResetPin, modemSleepRqPin, wifiId, wifiPwd,
espSleepRqPin,
espStatusPin // Optional arguments
);
EspressifESP8266 modemESP(&modemSerial, modemVccPin, modemResetPin, wifiId,
wifiPwd);
// Create an extra reference to the modem by a generic name
EspressifESP8266 modem = modemESP;
/** End [espressif_esp8266] */
Expand Down
149 changes: 11 additions & 138 deletions src/modems/EspressifESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@

// Constructors
EspressifESP8266::EspressifESP8266(Stream* modemStream, int8_t powerPin,
int8_t statusPin, int8_t modemResetPin,
int8_t modemSleepRqPin, const char* ssid,
const char* pwd, int8_t espSleepRqPin,
int8_t espStatusPin)
: loggerModem(powerPin, statusPin, ESP8266_STATUS_LEVEL, modemResetPin,
ESP8266_RESET_LEVEL, ESP8266_RESET_PULSE_MS, modemSleepRqPin,
int8_t modemResetPin, const char* ssid,
const char* pwd)
: loggerModem(powerPin, -1, ESP8266_STATUS_LEVEL, modemResetPin,
ESP8266_RESET_LEVEL, ESP8266_RESET_PULSE_MS, -1,
ESP8266_WAKE_LEVEL, ESP8266_WAKE_PULSE_MS,
ESP8266_STATUS_TIME_MS, ESP8266_DISCONNECT_TIME_MS,
ESP8266_WAKE_DELAY_MS, ESP8266_ATRESPONSE_TIME_MS),
Expand All @@ -28,39 +26,10 @@ EspressifESP8266::EspressifESP8266(Stream* modemStream, int8_t powerPin,
#else
gsmModem(*modemStream),
#endif
gsmClient(gsmModem) {
_ssid = ssid;
_pwd = pwd;

_espSleepRqPin = espSleepRqPin;
_espStatusPin = espStatusPin;

_modemStream = modemStream;
}
EspressifESP8266::EspressifESP8266(Stream* modemStream, int8_t powerPin,
int8_t statusPin, int8_t modemResetPin,
const char* ssid, const char* pwd,
int8_t modemSleepRqPin, int8_t espSleepRqPin,
int8_t espStatusPin)
: loggerModem(powerPin, statusPin, ESP8266_STATUS_LEVEL, modemResetPin,
ESP8266_RESET_LEVEL, ESP8266_RESET_PULSE_MS, modemSleepRqPin,
ESP8266_WAKE_LEVEL, ESP8266_WAKE_PULSE_MS,
ESP8266_STATUS_TIME_MS, ESP8266_DISCONNECT_TIME_MS,
ESP8266_WAKE_DELAY_MS, ESP8266_ATRESPONSE_TIME_MS),
#ifdef MS_ESPRESSIFESP8266_DEBUG_DEEP
_modemATDebugger(*modemStream, DEEP_DEBUGGING_SERIAL_OUTPUT),
gsmModem(_modemATDebugger),
#else
gsmModem(*modemStream),
#endif
gsmClient(gsmModem) {
_ssid = ssid;
_pwd = pwd;

_espSleepRqPin = espSleepRqPin;
_espStatusPin = espStatusPin;

_modemStream = modemStream;
gsmClient(gsmModem),
_modemStream(modemStream),
_ssid(ssid),
_pwd(pwd) {
}

// Destructor
Expand Down Expand Up @@ -91,7 +60,8 @@ bool EspressifESP8266::ESPwaitForBoot(void) {
delay(200); // It will take at least this long
uint32_t start = millis();
bool success = false;
while (!_modemStream->available() && millis() - start < 1000) {}
while (!_modemStream->available() && millis() - start < 1000) { /* wait */
}
if (_modemStream->available()) {
success = true;
// Read the boot log to empty it from the serial buffer
Expand All @@ -103,7 +73,6 @@ bool EspressifESP8266::ESPwaitForBoot(void) {
return success;
}


// Create the wake and sleep methods for the modem
// These can be functions of any type and must return a boolean
bool EspressifESP8266::modemWakeFxn(void) {
Expand Down Expand Up @@ -138,122 +107,26 @@ bool EspressifESP8266::modemWakeFxn(void) {
}
}


bool EspressifESP8266::modemSleepFxn(void) {
// Use this if you have GPIO16 connected to the reset pin to wake from deep
// sleep but no other MCU pin connected to the reset pin. NOTE: This will
// NOT work nicely with "testingMode"
/*if (loggingInterval > 1)
{
uint32_t sleepSeconds = (((uint32_t)loggingInterval) * 60 * 1000) -
75000L; String sleepCommand = String(sleepSeconds);
gsmModem.sendAT(GF("+GSLP="), sleepCommand);
// Power down for 1 minute less than logging interval
// Better: Calculate length of loop and power down for logging interval
- loop time return gsmModem.waitResponse() == 1;
}*/
// Use this if you have an MCU pin connected to the ESP's reset pin to wake
// from deep sleep We'll also put it in deep sleep before yanking power
// from deep sleep. We'll also put it in deep sleep before yanking power.
if (_modemResetPin >= 0 || _powerPin >= 0) {
MS_DBG(F("Requesting deep sleep for ESP8266"));
bool retVal = gsmModem.poweroff();
if (_modemSleepRqPin >= 0) {
digitalWrite(_modemSleepRqPin, !_wakeLevel);
}
return retVal;
} else if (_modemSleepRqPin >= 0 && _statusPin >= 0) {
// Use this if you don't have access to the ESP8266's reset pin for deep
// sleep but you do have access to another GPIO pin for light sleep.
// This also sets up another pin to view the sleep status.
// AT+WAKEUPGPIO=<enable>,<trigger_GPIO>,<trigger_level>[,<awake_GPIO>,<awake_level>]
// <enable>
// 1: ESP8266 can be woken up from light-sleep by GPIO.
// <trigger_GPIO>
// Sets the GPIO to wake ESP8266 up; range of value: [0, 15].
// <trigger_level>
// 0: The GPIO wakes up ESP8266 on low level.
// [<awake_GPIO>]
// Optional; this parameter is used to set a GPIO as a flag of
// ESP8266’s being awoken form Light-sleep; range of value: [0, 15].
// [<awake_level>]
// Optional;
// 0: The GPIO is set to be low level after the wakeup process.
// 1: The GPIO is set to be high level after the wakeup process.
// After being woken up by <trigger_GPIO> from Light-sleep, when the
// ESP8266 attempts to sleep again, it will check the status of the
// <trigger_GPIO>:
// - if it is still in the wakeup status, the EP8266 will enter
// Modem-sleep mode instead;
// - if it is NOT in the wakeup status, the ESP8266 will enter
// Light-sleep mode.
MS_DBG(F("Setting pin"), _modemSleepRqPin,
_statusLevel ? F("HIGH") : F("LOW"),
F("to allow ESP8266 to enter light sleep"));
digitalWrite(_modemSleepRqPin, !_wakeLevel);
MS_DBG(F("Requesting light sleep for ESP8266 with status indication"));
gsmModem.sendAT(GF("+WAKEUPGPIO=1,"), String(_espSleepRqPin), F(",0,"),
String(_espStatusPin), ',', _statusLevel);
bool success = gsmModem.waitResponse() == 1;
gsmModem.sendAT(GF("+SLEEP=1"));
success &= gsmModem.waitResponse() == 1;
delay(5);
return success;
} else if (_modemSleepRqPin >= 0 && _statusPin < 0) {
// Light sleep without the status pin
MS_DBG(F("Configuring light sleep for ESP8266"));
gsmModem.sendAT(GF("+WAKEUPGPIO=1,"), String(_espSleepRqPin), F(",0"));
bool success = gsmModem.waitResponse() == 1;
gsmModem.sendAT(GF("+SLEEP=1"));
success &= gsmModem.waitResponse() == 1;
delay(5);
MS_DBG(F("Setting pin"), _modemSleepRqPin,
!_wakeLevel ? F("HIGH") : F("LOW"),
F("to allow ESP8266 to enter light sleep"));
digitalWrite(_modemSleepRqPin, !_wakeLevel);
MS_DBG(F("Module MIGHT enter light sleep mode if it has been idle for "
"sufficient time."));
return success;
} else { // DON'T go to sleep if we can't wake up!
return true;
}
}


// Set up the light-sleep status pin, if applicable
bool EspressifESP8266::extraModemSetup(void) {
if (_modemSleepRqPin >= 0) { digitalWrite(_modemSleepRqPin, !_wakeLevel); }
gsmModem.init();
gsmClient.init(&gsmModem);
_modemName = gsmModem.getModemName();
// // And make sure we're staying in station mode so sleep can happen
// gsmModem.sendAT(GF("+CWMODE_DEF=1"));
// gsmModem.waitResponse();
// // Make sure that, at minimum, modem-sleep is on
// gsmModem.sendAT(GF("+SLEEP=2"));
// gsmModem.waitResponse();
// // Set the wifi settings as default
// // This will speed up connecting after resets
// gsmModem.sendAT(GF("+CWJAP_DEF=\""), _ssid, GF("\",\""), _pwd, GF("\""));
// if (gsmModem.waitResponse(30000L, GFP(GSM_OK), GF(GSM_NL "FAIL" GSM_NL))
// !=
// 1) {
// gsmModem.sendAT(GF("+CWJAP=\""), _ssid, GF("\",\""), _pwd, GF("\""));
// if (gsmModem.waitResponse(30000L, GFP(GSM_OK),
// GF(GSM_NL "FAIL" GSM_NL)) != 1) {
// return false;
// }
// }
// Slow down the baud rate for slow processors - and save the change to
// the ESP's non-volatile memory so we don't have to do it every time
// #if F_CPU == 8000000L
// if (modemBaud > 57600)
// {
// _modemSerial->begin(modemBaud);
// gsmModem.sendAT(GF("+UART_DEF=9600,8,1,0,0"));
// gsmModem.waitResponse();
// _modemSerial->end();
// _modemSerial->begin(9600);
// }
// #endif
return true;
}
Loading

0 comments on commit 194d2f9

Please sign in to comment.