Browse Source

add #114 ntp_server_name and port to eeprom

pull/126/head
stefan123t 2 years ago
parent
commit
2c177fbfa8
  1. 23
      tools/esp8266/app.cpp
  2. 8
      tools/esp8266/defines.h
  3. 6
      tools/esp8266/html/setup.html
  4. 4
      tools/esp8266/main.cpp
  5. 6
      tools/esp8266/main.h

23
tools/esp8266/app.cpp

@ -107,7 +107,6 @@ void app::setup(uint32_t timeout) {
mSys->Radio.pinIrq = RF24_IRQ_PIN;
}
// nrf24 amplifier power
mEep->read(ADDR_RF24_AMP_PWR, &mSys->Radio.AmplifierPower);
@ -122,6 +121,12 @@ void app::setup(uint32_t timeout) {
mSerialDebug = (tmp == 0x01);
mSys->Radio.mSerialDebug = mSerialDebug;
// ntp
char ntpAddr[NTP_ADDR_LEN];
uint16_t ntpPort;
mEep->read(ADDR_NTP_ADDR, ntpAddr, NTP_ADDR_LEN);
mEep->read(ADDR_NTP_PORT, &ntpPort);
// TODO set ntpAddr & ntpPort in main
// mqtt
uint16_t mqttPort;
@ -358,6 +363,7 @@ void app::loop(void) {
yield();
if(mSerialDebug)
DPRINTLN(DBG_DEBUG, F("app:loop WiFi WiFi.status ") + String(WiFi.status()) );
DPRINTLN(DBG_INFO, F("Requesting Inverter SN ") + String(iv->serial.u64, HEX));
mSys->Radio.sendTimePacket(iv->radioId.u64, mPayload[iv->id].ts);
mRxTicker = 0;
@ -579,6 +585,13 @@ void app::showSetup(void) {
mEep->read(ADDR_SER_DEBUG, &tmp);
html.replace(F("{SER_DBG_CB}"), (tmp == 0x01) ? "checked" : "");
char ntpAddr[NTP_ADDR_LEN] = {0};
uint16_t ntpPort;
mEep->read(ADDR_NTP_ADDR, ntpAddr, NTP_ADDR_LEN);
mEep->read(ADDR_NTP_PORT, &ntpPort);
html.replace(F("{NTP_ADDR}"), String(ntpAddr));
html.replace(F("{NTP_PORT}"), String(ntpPort));
char mqttAddr[MQTT_ADDR_LEN] = {0};
uint16_t mqttPort;
mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN);
@ -837,6 +850,14 @@ void app::saveValues(bool webSend = true) {
mSys->Radio.AmplifierPower = mWeb->arg("rf24Power").toInt() & 0x03;
mEep->write(ADDR_RF24_AMP_PWR, mSys->Radio.AmplifierPower);
// ntp
char ntpAddr[NTP_ADDR_LEN] = {0};
uint16_t ntpPort;
mWeb->arg("ntpAddr").toCharArray(ntpAddr, NTP_ADDR_LEN);
ntpPort = mWeb->arg("ntpPort").toInt();
mEep->write(ADDR_NTP_ADDR, ntpAddr, NTP_ADDR_LEN);
mEep->write(ADDR_NTP_PORT, ntpPort);
// mqtt
char mqttAddr[MQTT_ADDR_LEN] = {0};
uint16_t mqttPort;

8
tools/esp8266/defines.h

@ -58,6 +58,9 @@ typedef struct {
#define RF24_AMP_PWR_LEN 1
#define NTP_ADDR_LEN 32 // DNS Name
#define NTP_PORT_LEN 2 // uint16_t
#define MQTT_ADDR_LEN 32 // DNS Name
#define MQTT_USER_LEN 16
#define MQTT_PWD_LEN 32
@ -90,7 +93,10 @@ typedef struct {
#define ADDR_INV_INTERVAL ADDR_INV_CH_NAME + INV_CH_CH_NAME_LEN
#define ADDR_INV_MAX_RTRY ADDR_INV_INTERVAL + INV_INTERVAL_LEN
#define ADDR_MQTT_ADDR ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN
#define ADDR_NTP_ADDR ADDR_INV_MAX_RTRY + INV_MAX_RTRY_LEN
#define ADDR_NTP_PORT ADDR_NTP_ADDR + NTP_ADDR_LEN
#define ADDR_MQTT_ADDR ADDR_NTP_PORT + NTP_PORT_LEN
#define ADDR_MQTT_USER ADDR_MQTT_ADDR + MQTT_ADDR_LEN
#define ADDR_MQTT_PWD ADDR_MQTT_USER + MQTT_USER_LEN
#define ADDR_MQTT_TOPIC ADDR_MQTT_PWD + MQTT_PWD_LEN

6
tools/esp8266/html/setup.html

@ -83,6 +83,12 @@
<label for="rf24Power">Amplifier Power Level</label>
<select name="rf24Power">{RF24}</select>
<p class="des">NTP Server</p>
<label for="ntpAddr">NTP Server / IP</label>
<input type="text" class="text" name="ntpAddr" value="{NTP_ADDR}"/>
<label for="ntpPort">NTP Port</label>
<input type="text" class="text" name="ntpPort" value="{NTP_PORT}"/>
<p class="des">MQTT</p>
<label for="mqttAddr">Broker / Server IP</label>
<input type="text" class="text" name="mqttAddr" value="{MQTT_ADDR}"/>

4
tools/esp8266/main.cpp

@ -391,8 +391,8 @@ time_t Main::getNtpTime(void) {
uint8_t buf[NTP_PACKET_SIZE];
uint8_t retry = 0;
WiFi.hostByName (TIMESERVER_NAME, timeServer);
mUdp->begin(TIME_LOCAL_PORT);
WiFi.hostByName(NTP_SERVER_NAME, timeServer);
mUdp->begin(NTP_LOCAL_PORT);
sendNTPpacket(timeServer);

6
tools/esp8266/main.h

@ -26,9 +26,9 @@
const byte mDnsPort = 53;
/* TIMESERVER CONFIG */
#define TIMESERVER_NAME "pool.ntp.org"
#define TIME_LOCAL_PORT 8888
/* NTP TIMESERVER CONFIG */
#define NTP_SERVER_NAME "pool.ntp.org"
#define NTP_LOCAL_PORT 8888
#define NTP_PACKET_SIZE 48
#define TIMEZONE 1 // Central European time +1

Loading…
Cancel
Save