Fixed som HTML and JS problems. Removed external NTP library and using espressif internal NTP client instead

This commit is contained in:
Gunnar Skjold 2020-05-10 12:29:00 +02:00
parent efa99f970c
commit 778daf8645
5 changed files with 17 additions and 20 deletions

View File

@ -4,7 +4,7 @@ extra_configs = platformio-user.ini
[common]
framework = arduino
lib_deps = HanReader@1.0.1, ArduinoJson@6.14.1, MQTT@2.4.7, DallasTemperature@3.8.1, EspSoftwareSerial@6.7.1, Base64@1.0.0, RemoteDebug@3.0.5, Time@1.6, NTPClient@3.1.0
lib_deps = HanReader@1.0.1, ArduinoJson@6.14.1, MQTT@2.4.7, DallasTemperature@3.8.1, EspSoftwareSerial@6.7.1, Base64@1.0.0, RemoteDebug@3.0.5, Time@1.6
[env:hw1esp12e]
platform = espressif8266@2.3.3

View File

@ -22,7 +22,7 @@
#include <ArduinoJson.h>
#include <MQTT.h>
#include <DNSServer.h>
#include <NTPClient.h>
#include <TZ.h>
#if defined(ESP8266)
ADC_MODE(ADC_VCC);
@ -48,9 +48,6 @@ HwTools hw;
DNSServer dnsServer;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 3600, 60000);
AmsConfiguration config;
RemoteDebug Debug;
@ -235,7 +232,8 @@ void setup() {
if(config.hasConfig()) {
if(Debug.isActive(RemoteDebug::INFO)) config.print(&Debug);
WiFi_connect();
timeClient.begin();
configTime(TZ_Europe_Oslo, "pool.ntp.org");
//sntp_servermode_dhcp(0); // 0: disable obtaining SNTP servers from DHCP (enabled by default)
} else {
if(Debug.isActive(RemoteDebug::INFO)) {
debugI("No configuration, booting AP");
@ -327,8 +325,6 @@ void loop() {
errorBlink();
}
timeClient.update();
if (strlen(config.getMqttHost()) > 0) {
mqtt.loop();
delay(10); // Needed to preserve power. After adding this, the voltage is super smooth on a HAN powered device
@ -840,8 +836,6 @@ void MQTT_connect() {
if(config.isMqttSsl()) {
debugI("MQTT SSL is configured");
if(!timeClient.update()) debugW("NTP time is not ready");
secureClient = new WiFiClientSecure();
#if defined(ESP8266)
secureClient->setBufferSizes(512, 512);
@ -881,8 +875,9 @@ void MQTT_connect() {
#if defined(ESP8266)
if(secureClient) {
debugD("Setting NTP time for secure MQTT connection");
secureClient->setX509Time(timeClient.getEpochTime());
time_t epoch = time(nullptr);
debugD("Setting NTP time %i for secure MQTT connection", epoch);
secureClient->setX509Time(epoch);
}
#endif

View File

@ -69,6 +69,12 @@ $(function() {
$('#authSecurity').trigger('change');
// For file upload
$('#fileUploadField').on('change',function(){
var fileName = $(this).val();
$(this).next('.custom-file-label').html(fileName);
})
switch(window.location.pathname) {
case '/config-meter':
$('#config-meter-link').addClass('active');

View File

@ -2,6 +2,8 @@
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="gaugemeter.js"></script>
<script src="application.js"></script>

View File

@ -7,16 +7,10 @@
<span class="input-group-text">Upload</span>
</div>
<div class="custom-file">
<input name="file" type="file" class="custom-file-input" id="inputGroupFile01">
<label class="custom-file-label" for="inputGroupFile01">Choose file</label>
<input name="file" type="file" class="custom-file-input" id="fileUploadField">
<label class="custom-file-label" for="fileUploadField">Choose file</label>
</div>
</div>
<script>
$('#inputGroupFile01').on('change',function(){
var fileName = $(this).val();
$(this).next('.custom-file-label').html(fileName);
})
</script>
</div>
</div>
</div>