Community
OpenEnergyMonitor

Community

Use custom NTP server on the WiFi relay

Hello Community and staff at openenergymonitor!

We purchased an WiFi MQTT Relay / Thermostat from the webshop. We noticed that there’s no way to
enter a custom NTP server address thorugh the web interface. Please point me into the right direction in order to set up the unit to use our own internal NTP server as a time source (or use the NTP values provided by our internal DHCP server). We can use the UART for this one time setting, if you provide us the syntax.
The reason is because the unit is part of a subnet which is not allowed to reach the public internet. There’s a GPS-based NTP server in the local network there, and we need to have the unit sync to that.

We use the latest oem.v3190.bin firmware.

Thanks in advance for your answer.

Hello @Robi unfortunatly the default firmware on the Wifi Relay is Martin Harizanov’s closed source firmware, so I dont think there’s an easy way to modify that, @glyn.hudson might have an idea?

You could use the EmonESP open source firmware that we have developed that is also compatible with the WIFI Relay, it doesnt have all the same features but allows on/off and timer control via MQTT. You will want the timer branch:

https://github.com/openenergymonitor/EmonESP/tree/timer

Change L69 of src.ino:
https://github.com/openenergymonitor/EmonESP/blob/timer/src/src.ino#L69
to:

node_type = "wifirelay";
node_description = "WifiRelay";

and then set the time server here:
https://github.com/openenergymonitor/EmonESP/blob/timer/src/src.ino#L39

NTPClient timeClient(ntpUDP,"europe.pool.ntp.org",time_offset,60000);

To compile and upload the code you can use platformio:

pio run -t upload
pio run -t uploadfs

see notes for the sonoffS20:
https://github.com/openenergymonitor/EmonESP/blob/timer/sonoffS20.md

Thank you.
I’ve bought the WiFi Relay especially because it has fine-tuning possibilities for the hysteresis value of the thermostat. Does EmonESP have a thermostat feature with good hysteresis settings?

I’m afraid there is no easy way to modify @Martin_Harizanov WiFi relay firmware.

No it doesn’t, it’s only got basic on/off.

However, there is an open source version of the WiFi relay firmware which could be modified to add your own NTP:

Maybe an easier option would be to modify the firewall rules to only allow NTP access to this unit? Or setup another device to re-direct your local NTP to the NTP server the WiFi relay is expecting?

I apologize for this, we would be happy to give you a refund on the WiFi relay board if you would prefer not to pursue this.

It would be good to merge the thermostat features from the ESP8266_Relay_Board firmware at some point into the more actively developed EmonESP firmware…

Dear Glyn

Thanks for your support. The relay board is an excellent piece of hardware thus I wouldn’t give up so quickly. I have experence with Sonoffs and Tasmota but all I did so far was to upload ready-compiled firmware on these. Sonoffs are not even close - as far as their build quality is concerned.

At the moment I’m not ready to compile my own firmware from the source code you just linked, but I definitely want to try it out. Can you please point me in the right direction?
I use Linux on my computers.

Robert

I added NTP server setting in the configuration menu:

I have NOT tested the firmware, please try the following and report if it works:

Erase the flash
esptool.py --port /dev/ttyUSB0 --baud 230400 write_flash --flash_freq 40m --flash_mode qio --flash_size 16m-c1 0x00000 blank.bin 0x01000 blank.bin 0x7C000 esp_init_data_default.bin 0x7D000 blank.bin 0x7E000 blank.bin 0x7F000 blank.bin 0x80000 blank.bin 0xFE000 blank.bin 0xFC000 blank.bin 0x100000 blank.bin 0x101000 blank.bin 0x1FC000 esp_init_data_default.bin 0x1FD000 blank.bin 0x1FE000 blank.bin 0x1FF000 blank.bin

Then upload the new firmware:
esptool.py --port /dev/ttyUSB0 --baud 230400 write_flash --flash_freq 40m --flash_mode qio --flash_size 16m-c1 0x000000 "boot_v1.7.bin" 0x001000 v3360.oem.bin

v3360.oem.bin (389.6 KB) blank.bin (4 KB) boot_v1.7.bin (4.0 KB) esp_init_data_default.bin (128 Bytes)

3 Likes

Woaaah! Testing right away. Hold on a couple of minutes.

That’s @Martin_Harizanov, that’s awesome! :+1:

1 Like

Martin,

I was able to restore the wifi relay with these files. I see the field to add a custom NTP server - thank you.
Unfortunately the device doesn’t update time at all.
It doesn’t initiate any NTP client connection at all - as inspected using packet capture (aka. wireshark). (This behaviour was the same in the previous v3190 version too, didn’t contact pool.ntp.org at all)
See below a capture made on the firewall itself, straight after powering on the unit:

19:29:45.197392 dc:4f:22:40:ba:a5 > ff:ff:ff:ff:ff:ff Null Supervisory, Receiver not Ready, rcv seq 64, Flags [Poll], length 42
19:29:45.222707 IP 0.0.0.0.68 > 255.255.255.255.67: UDP, length 308
19:29:45.222843 IP 172.22.215.254.67 > 172.22.215.18.68: UDP, length 300
19:29:45.228543 IP 0.0.0.0.68 > 255.255.255.255.67: UDP, length 308
19:29:45.228659 IP 172.22.215.254.67 > 172.22.215.18.68: UDP, length 300
19:29:45.233869 ARP, Request who-has 172.22.215.18 tell 0.0.0.0, length 42
19:29:45.572315 ARP, Request who-has 172.22.215.18 tell 0.0.0.0, length 42
19:29:46.072586 ARP, Request who-has 172.22.215.18 tell 172.22.215.18, length 42
19:29:46.780197 ARP, Request who-has 172.22.215.60 tell 172.22.215.18, length 42
19:30:13.109514 dc:4f:22:40:ba:a5 > ff:ff:ff:ff:ff:ff Null Supervisory, Receiver not Ready, rcv seq 64, Flags [Poll], length 42
19:30:13.126688 IP 0.0.0.0.68 > 255.255.255.255.67: UDP, length 308
19:30:13.126807 IP 172.22.215.254.67 > 172.22.215.18.68: UDP, length 300
19:30:13.133956 IP 0.0.0.0.68 > 255.255.255.255.67: UDP, length 308
19:30:13.134037 IP 172.22.215.254.67 > 172.22.215.18.68: UDP, length 300
19:30:13.136552 ARP, Request who-has 172.22.215.18 tell 0.0.0.0, length 42
19:30:13.502191 ARP, Request who-has 172.22.215.18 tell 0.0.0.0, length 42
19:30:14.002155 ARP, Request who-has 172.22.215.18 tell 172.22.215.18, length 42
19:30:14.741276 ARP, Request who-has 172.22.215.60 tell 172.22.215.18, length 42

172.22.215.254 is the gateway/dhcp/ntp server. 172.22.215.18 is the wifi relay. As you can see, only DHCP messages are initiated by the relay, nothing else.

Also the other issue is still present: If I change the name of the relay, it won’t connect to the wifi after reboot. Need to set it to AP mode with the button, enter network key again and after that, it’s going to be fine.
Time is always 00:00:00 01/01/1970 , DST: 0 and also Uptime: 0 days, 0 hours, 0 minutes, 0 seconds doesn’t increase.
GMT offset and DST auto adjust are not saved.
(these were all present in v3190 too!)

That’s odd. Here is what it looks here:


It is picking up time, GMT offset and DST auto changes are saved. Wifi works just fine after renaming the relay…

I suspect browser issue, can you try incognito mode/clean profile with no plugins Chrome or Firefox?

NTP is notoriously problematic for IoT, check my finding here: https://harizanov.com/2019/01/thoughts-on-time-date-management-on-iot-nodes/

1 Like

Another idea: wireshark not capturing the NTP requests may mean the NTP server name isn’t resolved. I’d try few different NTP servers to check this theory https://tf.nist.gov/tf-cgi/servers.cgi

Question: does your relay sync time strainght after connecting to the wifi network, in the default settings state?

Mine doesn’t.

Does it make a difference that my WiFi key is 63 characters long?

I specified the NTP server as an IP address, 172.22.215.254.

Specifying IP address won’t work, it isn’t that smart yet. Use server name.

The ssid/key are limited to 31(+1 for terminator):

33

I think we have reached to the root cause of your troubles

1 Like

Trying now using Chromium browser incognito mode.
Reset to factory defaults. I want to note first that I’m using it with DHCP only, using static lease based on MAC address.
When in AP mode, i see in wifi settings the IP address pre-filled with 192.168.1.10. After connected to the network, re-visiting the WiFi settings page I see the IP address field containing 68.50.89.53, mask 52.48.118.53, gw 55.70.69.45.

OH! Would it be possible to expand that to 64 characters, as the maximum allowed by the standard?
I already have all my other IOT devices connected to this network…

these are the ascii charaters of your 64 byte password overflowing to the next config…

1 Like

IMHO the IEEE standard states 32 bytes

It’s not the SSID, it’s the KEY/Password which is 63 chars long. According to the standard that can be 63 characters in WPA mode.