/broker/time added

pull/16/head
Martin Ger 2017-07-13 10:41:58 +02:00
rodzic 0b7be38fb1
commit de37f8c3d7
6 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -87,6 +87,9 @@ Advanced commands:
- set ap_on [0|1]: selects, whether the soft-AP is disabled (ap_on=0) or enabled (ap_on=1, default)
- set ap_open [0|1]: selects, whether the soft-AP uses WPA2 security (ap_open=0, automatic, if an ap_password is set) or open (ap_open=1)
- set speed [80|160]: sets the CPU clock frequency (default 80 Mhz)
- set ntp_server _IP_or_hostname_: sets the name or IP of an NTP server ("none" disables NTP, default)
- set ntp_interval _interval_: sets the NTP sync interval in seconds (default 60)
- set ntp_timezone _tz_: sets the timezone in hours offset
While the user interface looks similar to my esp_wifi_repeater at https://github.com/martin-ger/esp_wifi_repeater this does NO NAT routing. AP and STA network are stricly separated and there is no routing in between. The only possible connection via both networks is the uMQTT broker that listens on both interfaces.
@ -113,3 +116,8 @@ You can test this with the commands:
- unsubscribe [local|remote] [topic]: unsubscribes from a topic
Currently the clients republish everything they receive (and they have subscribed) to the other client, thus it can act as something like an MQTT bridge. Up to now, the subscriptions are not persistently saved to config, so they have to be entered manually after each reboot - will work on this...
# NTP Support
Remote NTP time servers are supported. By default the NTP client is disabled - and the is no immediate need for synced time. Nowever, it can be enabled by setting the config parameter "ntp_server" to a hostname or IP different from "none" ("1.pool.ntp.org" is a good choice). Also you can set the "ntp_timezone" to an offset from GMT. The system time will be synced with the NTP server every "ntp_interval" seconds. Here it uses NOT the full NTP calculation and clock drift compensation. Instead it will just set the local time to the latest received time.
After NTP sync has been completed successful once, the local time will be published every second under the topic "$SYS/broker/time" in the format "hh:mm:ss". You can also query the NTP time with the "time" command from the commandline.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -138,6 +138,11 @@ void ICACHE_FLASH_ATTR ntp_set_server(uint8_t *ntp_server) {
}
bool ICACHE_FLASH_ATTR ntp_sync_done() {
return t_offset!=0;
}
void ICACHE_FLASH_ATTR ntp_get_time() {
ntp_t ntp;

Wyświetl plik

@ -19,6 +19,7 @@ typedef struct {
} ntp_t;
void ntp_set_server(uint8_t *ntp_server);
bool ntp_sync_done();
void ntp_get_time();
void get_cur_time(struct timeval *tv);
uint8_t *get_timestr(int16_t timezone);

Wyświetl plik

@ -779,14 +779,9 @@ static void ICACHE_FLASH_ATTR tcp_client_connected_cb(void *arg)
#endif /* REMOTE_CONFIG */
bool toggle;
// Timer cb function
void ICACHE_FLASH_ATTR timer_func(void *arg){
uint32_t Vcurr;
uint64_t t_new;
uint32_t t_diff;
toggle = !toggle;
// Do we still have to configure the AP netif?
if (do_ip_config) {
@ -800,9 +795,12 @@ uint32_t t_diff;
ntp_get_time();
t_ntp_resync = t_new;
}
if (ntp_sync_done())
MQTT_local_publish("$SYS/broker/time", get_timestr(config.ntp_timezone), 8, 0, 0);
#endif
os_timer_arm(&ptimer, toggle?1000:100, 0);
os_timer_arm(&ptimer, 1000, 0);
}
//Priority 0 Task