This commit is contained in:
geeksville 2020-02-01 18:45:27 -08:00
parent de03dc88f4
commit 2474b3b064
7 changed files with 34 additions and 38 deletions

View File

@ -2,6 +2,7 @@
# High priority # High priority
* solder debug headers to board - debug sendTo hang bug
* make message send from android go to service, then to mesh radio * make message send from android go to service, then to mesh radio
* make message receive from radio go through to android * make message receive from radio go through to android
* have MeshService keep a node DB by sniffing user messages * have MeshService keep a node DB by sniffing user messages
@ -9,6 +10,7 @@
# Medium priority # Medium priority
* use https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/ association sleep pattern to save power - but see https://github.com/espressif/esp-idf/issues/2070
* correctly map nodeids to nodenums, currently we just do a proof of concept by always doing a broadcast * correctly map nodeids to nodenums, currently we just do a proof of concept by always doing a broadcast
* add interrupt detach/sleep mode config to lora radio so we can enable deepsleep without panicing * add interrupt detach/sleep mode config to lora radio so we can enable deepsleep without panicing
* figure out if we can use PA_BOOST * figure out if we can use PA_BOOST
@ -21,6 +23,7 @@
# Pre-beta priority # Pre-beta priority
* do hibernation mode to get power draw down to 2.5uA https://lastminuteengineers.com/esp32-sleep-modes-power-consumption/
* make sure main cpu is not woken for packets with bad crc or not addressed to this node - do that in the radio hw * make sure main cpu is not woken for packets with bad crc or not addressed to this node - do that in the radio hw
* enable fast init inside the gps chip * enable fast init inside the gps chip
* dynamically select node nums * dynamically select node nums

View File

@ -23,6 +23,8 @@ board_build.partitions = partition-table.csv
build_flags = -Wall -Wextra -Wno-missing-field-initializers -O3 -Wl,-Map,.pio/build/esp32/output.map build_flags = -Wall -Wextra -Wno-missing-field-initializers -O3 -Wl,-Map,.pio/build/esp32/output.map
; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
lib_deps = lib_deps =

View File

@ -101,7 +101,7 @@ private:
} }
else else
{ {
radio.sendTo(p.to, outbuf, stream.bytes_written); assert(radio.sendTo(p.to, outbuf, stream.bytes_written) == ERRNO_OK);
} }
} }
}; };

View File

@ -20,7 +20,7 @@ NodeNum getDesiredNodeNum() {
uint8_t dmac[6]; uint8_t dmac[6];
esp_efuse_mac_get_default(dmac); esp_efuse_mac_get_default(dmac);
// FIXME // FIXME not the right way to guess node numes
uint8_t r = dmac[5]; uint8_t r = dmac[5];
assert(r != 0xff); // It better not be the broadcast address assert(r != 0xff); // It better not be the broadcast address
return r; return r;
@ -69,8 +69,14 @@ bool MeshRadio::init() {
ErrorCode MeshRadio::sendTo(NodeNum dest, const uint8_t *buf, size_t len) { ErrorCode MeshRadio::sendTo(NodeNum dest, const uint8_t *buf, size_t len) {
Serial.println("Sending..."); Serial.printf("mesh sendTo %d bytes to %d\n", len, dest);
return manager.sendtoWait((uint8_t *) buf, len, dest); // FIXME - for now we do all packets as broadcast
dest = NODENUM_BROADCAST;
// Note: we don't use sendToWait here because we don't want to wait and for the time being don't require
// reliable delivery
// return manager.sendtoWait((uint8_t *) buf, len, dest);
return manager.sendto((uint8_t *) buf, len, dest) ? ERRNO_OK : ERRNO_UNKNOWN;
} }
void MeshRadio::loop() { void MeshRadio::loop() {
@ -95,5 +101,5 @@ void mesh_loop()
char radiopacket[20] = "Hello World # "; char radiopacket[20] = "Hello World # ";
sprintf(radiopacket, "hello %d", packetnum++); sprintf(radiopacket, "hello %d", packetnum++);
radio.sendTo(NODENUM_BROADCAST, (uint8_t *)radiopacket, sizeof(radiopacket)); assert(radio.sendTo(NODENUM_BROADCAST, (uint8_t *)radiopacket, sizeof(radiopacket)) == ERRNO_OK);
} }

View File

@ -4,6 +4,8 @@
#include <RHMesh.h> #include <RHMesh.h>
#define NODENUM_BROADCAST 255 #define NODENUM_BROADCAST 255
#define ERRNO_OK 0
#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER
typedef int ErrorCode; typedef int ErrorCode;
typedef uint8_t NodeNum; typedef uint8_t NodeNum;

View File

@ -42,14 +42,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEBUG_PORT Serial // Serial debug port #define DEBUG_PORT Serial // Serial debug port
#define SERIAL_BAUD 115200 // Serial debug baud rate #define SERIAL_BAUD 115200 // Serial debug baud rate
#define SLEEP_BETWEEN_MESSAGES false // Do sleep between messages #define SLEEP_MSECS (5 * 60 * 1000) // Sleep for these many millis (or a button press or a lora msg?)
#define SEND_INTERVAL (5 * 60 * 1000) // Sleep for these many millis
#define MESSAGE_TO_SLEEP_DELAY 5000 // Time after message before going to sleep #define MESSAGE_TO_SLEEP_DELAY 5000 // Time after message before going to sleep
#define LOGO_DELAY 5000 // Time to show logo on first boot #define LOGO_DELAY 5000 // Time to show logo on first boot
#define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found #define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found
// If not defined, we will wait for lock forever // If not defined, we will wait for lock forever
#define GPS_WAIT_FOR_LOCK (60 * 1000) // Wait after every boot for GPS lock (may need longer than 5s because we turned the gps off during deep sleep) #define MINWAKE_MSECS (30 * 1000) // Wait after every boot for GPS lock (may need longer than 5s because we turned the gps off during deep sleep)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// DEBUG // DEBUG

View File

@ -58,7 +58,7 @@ void doDeepSleep(uint64_t msecToWake)
screen_off(); // datasheet says this will draw only 10ua screen_off(); // datasheet says this will draw only 10ua
// FIXME, shutdown radio headinterups before powering off device // FIXME, shutdown radiohead interrupts before powering off device
#ifdef T_BEAM_V10 #ifdef T_BEAM_V10
if (axp192_found) if (axp192_found)
@ -69,6 +69,10 @@ void doDeepSleep(uint64_t msecToWake)
} }
#endif #endif
#ifdef VEXT_ENABLE
digitalWrite(VEXT_ENABLE, 1); // turn off the display power
#endif
// FIXME - use an external 10k pulldown so we can leave the RTC peripherals powered off // FIXME - use an external 10k pulldown so we can leave the RTC peripherals powered off
// until then we need the following lines // until then we need the following lines
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
@ -89,7 +93,7 @@ void doDeepSleep(uint64_t msecToWake)
void sleep() void sleep()
{ {
#if SLEEP_BETWEEN_MESSAGES #ifdef SLEEP_MSECS
// If the user has a screen, tell them we are about to sleep // If the user has a screen, tell them we are about to sleep
if (ssd1306_found) if (ssd1306_found)
@ -101,15 +105,11 @@ void sleep()
// Wait for MESSAGE_TO_SLEEP_DELAY millis to sleep // Wait for MESSAGE_TO_SLEEP_DELAY millis to sleep
delay(MESSAGE_TO_SLEEP_DELAY); delay(MESSAGE_TO_SLEEP_DELAY);
// Turn off screen
screen_off();
} }
// We sleep for the interval between messages minus the current millis // We sleep for the interval between messages minus the current millis
// this way we distribute the messages evenly every SEND_INTERVAL millis // this way we distribute the messages evenly every SEND_INTERVAL millis
uint32_t sleep_for = (millis() < SEND_INTERVAL) ? SEND_INTERVAL - millis() : SEND_INTERVAL; doDeepSleep(SLEEP_MSECS);
doDeepSleep(sleep_for);
#endif #endif
} }
@ -313,11 +313,10 @@ void loop()
mesh_loop(); mesh_loop();
loopBLE(); loopBLE();
if (packetSent) #ifdef LED_PIN
{ // toggle the led so we can get some rough sense of how often loop is pausing
packetSent = false; digitalWrite(LED_PIN, digitalRead(LED_PIN) ? 0 : 1);
sleep(); #endif
}
#ifdef BUTTON_PIN #ifdef BUTTON_PIN
// if user presses button for more than 3 secs, discard our network prefs and reboot (FIXME, use a debounce lib instead of this boilerplate) // if user presses button for more than 3 secs, discard our network prefs and reboot (FIXME, use a debounce lib instead of this boilerplate)
@ -348,24 +347,10 @@ void loop()
// Send every SEND_INTERVAL millis // Send every SEND_INTERVAL millis
static uint32_t last = 0; static uint32_t last = 0;
static bool first = true; if (true)
if (0 == last || millis() - last > SEND_INTERVAL)
{ {
if (false) #ifdef MINWAKE_MSECS
{ if (millis() > MINWAKE_MSECS)
last = millis();
first = false;
Serial.println("TRANSMITTED");
}
else
{
if (first)
{
screen_print("Waiting GPS lock\n");
first = false;
}
#ifdef GPS_WAIT_FOR_LOCK
if (millis() > GPS_WAIT_FOR_LOCK)
{ {
sleep(); sleep();
} }
@ -375,5 +360,4 @@ void loop()
// i.e. don't just keep spinning in loop as fast as we can. // i.e. don't just keep spinning in loop as fast as we can.
delay(100); delay(100);
} }
}
} }