Skip to content

Commit

Permalink
synchronize with esp32 template
Browse files Browse the repository at this point in the history
  • Loading branch information
Juergen Pichlbauer committed Sep 25, 2022
1 parent 1426326 commit d005839
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Note that we do not subscribe to this topic, we only publish to it.

### Importance of `ClientName` Setting
Note that the `ClientName` configured in the `platformio.ini` file will also be used as the hostname reported to your DHCP server when the ESP fetches an IP-address. This is especially important, as OTA-flashing will also require your networking environment to be able to resolve this hostname to the ESP's IP-address!
See `upload_port`setting in the `platformio.ini` file. If you're having troubles with OTA-flashing, you might want to check that first by pinging the configured `ClientName`.
See `upload_port`setting in the `platformio.ini` file. If you're having troubles with OTA-flashing, you might want to check that first by pinging the configured `ClientName`.
**ATTENTION:** `ClientName` must not contain dashes.

### Compiling and flashing walkthrough
I will give a rough walkthrough on the first steps, assuming you have a working PlatformIO environment:
Expand Down Expand Up @@ -110,4 +111,6 @@ ATTN: OTA flashing did not work due to an error in macro handling!
- Major code cleanup

## Release 1.0.3
- Moved user specific stuff into dedicated files / functions (`user_setup` and `user_loop`)
- Moved user specific stuff into dedicated files / functions (`user_setup` and `user_loop`)
- Added `MqttDelay` function which handles MQTT connection/subscriptions while delaying
- README update on `ClientName` limitation
1 change: 1 addition & 0 deletions include/common-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern void MqttCallback(char *topic, byte *payload, unsigned int length);
extern bool MqttSubscribe(const char *Topic);
extern bool MqttConnectToBroker();
extern void MqttUpdater();
extern void MqttDelay(uint32_t delayms);
#ifdef OTA_UPDATE
extern bool OTAUpdateHandler();
#endif
Expand Down
1 change: 1 addition & 0 deletions include/mqtt-ota-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern unsigned int SubscribedTopics;
extern unsigned int ReceivedTopics;

// MQTT Topic Tree prepended to all topics
// ATTN: Must end with "/"!
#define TOPTREE "HB7/Test/"

// MQTT Topics and corresponding local vars
Expand Down
2 changes: 1 addition & 1 deletion include/user_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Don't forget to add them into platformio.ini
//#define <user_lib.h>

// Declare user setup and main loop functions
// Declare user setup, main and custom functions
extern void user_setup();
extern void user_loop();

Expand Down
27 changes: 27 additions & 0 deletions src/common-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,33 @@ void MqttUpdater()
}
}

// Function to periodically handle MQTT stuff while delaying
// This causes some inaccuracy in the delay of course.
void MqttDelay(uint32_t delayms)
{
//unsigned long md_start = millis();
// Call MqttUpdater every 200ms
int Counter = delayms / 200;
if (Counter == 0)
{
// Delay less than 200ms requested, just run delay and return
delay(delayms);
return;
}
else
{
for (int i = 0; i < Counter; i++)
{
MqttUpdater();
delay(200);
}
}
//unsigned long real_delay = millis() - md_start;
//DEBUG_PRINTLN("MqttDelay requested: " + String(delayms));
//DEBUG_PRINTLN("MqttDelay Counter: " + String(Counter));
//DEBUG_PRINTLN("MqttDelay duration: " + String(real_delay));
}

// Function to handle OTA flashing (called in main loop)
// Returns TRUE while OTA-update was requested or in progress
#ifdef OTA_UPDATE
Expand Down

0 comments on commit d005839

Please sign in to comment.