fix: MQTT tick not starting on connect and switch to esp_timer

- Tick should be updated on connect
- Dependency of system timer removed to avoid issues when updating via
  SNTP

Closes https://github.com/espressif/esp-mqtt/issues/225
This commit is contained in:
Euripedes Rocha
2022-06-06 12:52:22 -03:00
parent 493822dc9d
commit 89e5c6014f
3 changed files with 17 additions and 29 deletions

View File

@@ -3,8 +3,8 @@
#ifdef ESP_PLATFORM
#include "esp_log.h"
#include "esp_mac.h"
#include "esp_timer.h"
#include "esp_random.h"
#include <sys/time.h>
#include <stdlib.h>
#include <stdint.h>
@@ -27,18 +27,9 @@ int platform_random(int max)
return esp_random() % max;
}
int64_t platform_tick_get_ms(void)
uint64_t platform_tick_get_ms(void)
{
struct timeval te;
gettimeofday(&te, NULL); // get current time
long long milliseconds = te.tv_sec * 1000LL + te.tv_usec / 1000; // calculate milliseconds
// printf("milliseconds: %lld\n", milliseconds);
return milliseconds;
return esp_timer_get_time()/(int64_t)1000;
}
void ms_to_timeval(int timeout_ms, struct timeval *tv)
{
tv->tv_sec = timeout_ms / 1000;
tv->tv_usec = (timeout_ms - (tv->tv_sec * 1000)) * 1000;
}
#endif