sforkowany z mirror/meshtastic-firmware
progress
rodzic
de03dc88f4
commit
2474b3b064
3
TODO.md
3
TODO.md
|
@ -2,6 +2,7 @@
|
|||
|
||||
# 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 receive from radio go through to android
|
||||
* have MeshService keep a node DB by sniffing user messages
|
||||
|
@ -9,6 +10,7 @@
|
|||
|
||||
# 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
|
||||
* add interrupt detach/sleep mode config to lora radio so we can enable deepsleep without panicing
|
||||
* figure out if we can use PA_BOOST
|
||||
|
@ -21,6 +23,7 @@
|
|||
|
||||
# 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
|
||||
* enable fast init inside the gps chip
|
||||
* dynamically select node nums
|
||||
|
|
|
@ -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
|
||||
; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
|
||||
upload_speed = 921600
|
||||
|
||||
monitor_speed = 115200
|
||||
|
||||
lib_deps =
|
||||
|
|
|
@ -101,7 +101,7 @@ private:
|
|||
}
|
||||
else
|
||||
{
|
||||
radio.sendTo(p.to, outbuf, stream.bytes_written);
|
||||
assert(radio.sendTo(p.to, outbuf, stream.bytes_written) == ERRNO_OK);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ NodeNum getDesiredNodeNum() {
|
|||
uint8_t dmac[6];
|
||||
esp_efuse_mac_get_default(dmac);
|
||||
|
||||
// FIXME
|
||||
// FIXME not the right way to guess node numes
|
||||
uint8_t r = dmac[5];
|
||||
assert(r != 0xff); // It better not be the broadcast address
|
||||
return r;
|
||||
|
@ -69,8 +69,14 @@ bool MeshRadio::init() {
|
|||
|
||||
|
||||
ErrorCode MeshRadio::sendTo(NodeNum dest, const uint8_t *buf, size_t len) {
|
||||
Serial.println("Sending...");
|
||||
return manager.sendtoWait((uint8_t *) buf, len, dest);
|
||||
Serial.printf("mesh sendTo %d bytes to %d\n", 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() {
|
||||
|
@ -95,5 +101,5 @@ void mesh_loop()
|
|||
char radiopacket[20] = "Hello World # ";
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <RHMesh.h>
|
||||
|
||||
#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 uint8_t NodeNum;
|
||||
|
|
|
@ -42,14 +42,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#define DEBUG_PORT Serial // Serial debug port
|
||||
#define SERIAL_BAUD 115200 // Serial debug baud rate
|
||||
#define SLEEP_BETWEEN_MESSAGES false // Do sleep between messages
|
||||
#define SEND_INTERVAL (5 * 60 * 1000) // Sleep for these many millis
|
||||
#define SLEEP_MSECS (5 * 60 * 1000) // Sleep for these many millis (or a button press or a lora msg?)
|
||||
#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 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
|
||||
#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
|
||||
|
|
44
src/main.ino
44
src/main.ino
|
@ -58,7 +58,7 @@ void doDeepSleep(uint64_t msecToWake)
|
|||
|
||||
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
|
||||
if (axp192_found)
|
||||
|
@ -69,6 +69,10 @@ void doDeepSleep(uint64_t msecToWake)
|
|||
}
|
||||
#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
|
||||
// until then we need the following lines
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
@ -89,7 +93,7 @@ void doDeepSleep(uint64_t msecToWake)
|
|||
|
||||
void sleep()
|
||||
{
|
||||
#if SLEEP_BETWEEN_MESSAGES
|
||||
#ifdef SLEEP_MSECS
|
||||
|
||||
// If the user has a screen, tell them we are about to sleep
|
||||
if (ssd1306_found)
|
||||
|
@ -101,15 +105,11 @@ void sleep()
|
|||
|
||||
// Wait for MESSAGE_TO_SLEEP_DELAY millis to sleep
|
||||
delay(MESSAGE_TO_SLEEP_DELAY);
|
||||
|
||||
// Turn off screen
|
||||
screen_off();
|
||||
}
|
||||
|
||||
// We sleep for the interval between messages minus the current 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_for);
|
||||
doDeepSleep(SLEEP_MSECS);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -313,11 +313,10 @@ void loop()
|
|||
mesh_loop();
|
||||
loopBLE();
|
||||
|
||||
if (packetSent)
|
||||
{
|
||||
packetSent = false;
|
||||
sleep();
|
||||
}
|
||||
#ifdef LED_PIN
|
||||
// toggle the led so we can get some rough sense of how often loop is pausing
|
||||
digitalWrite(LED_PIN, digitalRead(LED_PIN) ? 0 : 1);
|
||||
#endif
|
||||
|
||||
#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)
|
||||
|
@ -348,24 +347,10 @@ void loop()
|
|||
|
||||
// Send every SEND_INTERVAL millis
|
||||
static uint32_t last = 0;
|
||||
static bool first = true;
|
||||
if (0 == last || millis() - last > SEND_INTERVAL)
|
||||
if (true)
|
||||
{
|
||||
if (false)
|
||||
{
|
||||
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)
|
||||
#ifdef MINWAKE_MSECS
|
||||
if (millis() > MINWAKE_MSECS)
|
||||
{
|
||||
sleep();
|
||||
}
|
||||
|
@ -375,5 +360,4 @@ void loop()
|
|||
// i.e. don't just keep spinning in loop as fast as we can.
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue