Skip to content

Commit

Permalink
Merge pull request #69 from omersiar/dev
Browse files Browse the repository at this point in the history
Hot fix #68
  • Loading branch information
omersiar authored Mar 6, 2018
2 parents c52075f + b6217bd commit bc7e5bd
Show file tree
Hide file tree
Showing 48 changed files with 1,069 additions and 971 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/websrc/3rdparty/* linguist-vendored
src/webh/* linguist-vendored
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json

# esp-rfid
src/websrc/css/required.css
src/websrc/js/required.js
src/websrc/fonts/*
src/websrc/gzipped
data/auth/config.json
.clang_complete
.gcc-flags.json

# node js

Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ All notable changes to this project will be documented in this file.

## [Unreleased]
#### Added
- **!!!! Breaking Change !!!!** [firmware] Factory reset on boot if GPIO-16 is LOW or SPIFFS is corrupted. Make changes accordingly.
- [webui] Touch detect on touch enabled devices in order to open/close sidebar on swipe.
- [webui] Logout is now live (this is actually a dirty hack);

#### Fixed
- [dev tools] - Websocket emulator time was static
- [firmware] #68 NTP functions cause Exception 9 and ESP crashes

#### Changed
- [webui] Embarrassing multiple HTM pages now reduced to one.
- [webui] Better representing of device and browser times on NTP settings.
- [webui] Prevent closing restore modal until it is finished.
- [firmware] Refactored NTP.

#### Removed
- [webui] Removed GPIO-16 options due to it is being used for Factory Reset
- [firmware] Drop usage of NTPClientLib.

## [0.5beta] - 2018-03-02
#### Added
- [firmware + webui] Embedded web files
- [firmware + webui] MQTT to main branch.
- [firmware + webui] Access column to logs for the information, if the access was granted or not @romanzava
Expand Down
Binary file modified bin/firmware.bin
Binary file not shown.
36 changes: 0 additions & 36 deletions lib/readme.txt

This file was deleted.

37 changes: 15 additions & 22 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,48 @@ env_default = nodemcu

[common]
platform = espressif8266
lib_deps_builtin =
ESP8266WiFi
SPI
ESP8266mDNS
lib_deps_external =
ArduinoJson
PubSubClient
https://github.com/me-no-dev/ESPAsyncTCP.git
https://github.com/me-no-dev/ESPAsyncWebServer
https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino.git
https://github.com/miguelbalboa/rfid
https://github.com/PaulStoffregen/Time
https://github.com/gmag11/NtpClient/
lib_deps =
ArduinoJson
PubSubClient
ESPAsyncTCP
ESP Async WebServer
Time
MFRC522
ESPAsyncUDP
https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino.git

; boards which GPIO0 and RESET controlled using two NPN transistors as nodemcu devkit (includes wemos d1 mini)
[env:nodemcu]
board_f_cpu = 160000000L
platform = ${common.platform}
framework = arduino
board = esp12e
upload_resetmethod = nodemcu
lib_deps =
${common.lib_deps_builtin}
${common.lib_deps_external}
lib_deps = ${common.lib_deps}
build_flags = -Wl,-Teagle.flash.4m.ld
extra_scripts = scripts/pio_script.py
upload_speed = 921600
; Serial Monitor options
monitor_baud = 115200

[env:deploy]
board_f_cpu = 160000000L
platform = ${common.platform}
framework = arduino
board = esp12e
lib_deps =
${common.lib_deps_builtin}
${common.lib_deps_external}
lib_deps = ${common.lib_deps}
extra_scripts = scripts/pio_script.py
build_flags = -Wl,-Teagle.flash.4m.ld
build_flags = !echo '-DBUILD_TAG='$TRAVIS_TAG

[env:dout]
board_f_cpu = 160000000L
platform = ${common.platform}
framework = arduino
board = esp12e
board_flash_mode = dout
upload_resetmethod = ck
lib_deps =
${common.lib_deps_builtin}
${common.lib_deps_external}
lib_deps = ${common.lib_deps}
build_flags = -Wl,-Teagle.flash.4m.ld
extra_scripts = scripts/pio_script.py
upload_speed = 921600
Expand Down
135 changes: 135 additions & 0 deletions src/Ntp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* ntp.cpp
*
* Created on: 8 Mar 2016
* Author: joe
*/

#include "Ntp.h"
#include <ESPAsyncUDP.h>

char * NtpClient::TimeServerName;
int8_t NtpClient::timezone;
time_t NtpClient::syncInterval;
IPAddress NtpClient::timeServer;

AsyncUDP NtpClient::udpListener;

byte NtpClient::NTPpacket[NTP_PACKET_SIZE];

void ICACHE_FLASH_ATTR NtpClient::Ntp(const char * server, int8_t tz, time_t syncSecs) {
TimeServerName = strdup(server);
timezone = tz;
syncInterval = syncSecs;
setSyncProvider(getNtpTime);
setSyncInterval(syncInterval);
}


ICACHE_FLASH_ATTR NtpClient::~NtpClient() {
udpListener.close();
}

// send an NTP request to the time server at the given address
time_t ICACHE_FLASH_ATTR NtpClient::getNtpTime() {
memset(NTPpacket, 0, sizeof(NTPpacket));
NTPpacket[0]=0b11100011;
NTPpacket[1]=0;
NTPpacket[2]=6;
NTPpacket[3]=0xEC;
NTPpacket[12]=49;
NTPpacket[13]=0x4E;
NTPpacket[14]=49;
NTPpacket[15]=52;
WiFi.hostByName(TimeServerName,timeServer);
if(udpListener.connect(timeServer, 123)) {
udpListener.onPacket([](AsyncUDPPacket packet) {
unsigned long highWord = word(packet.data()[40], packet.data()[41]);
unsigned long lowWord = word(packet.data()[42], packet.data()[43]);
time_t UnixUTCtime = (highWord << 16 | lowWord)-2208988800UL;
setTime(UnixUTCtime);
});
}
else {

}
udpListener.write(NTPpacket, sizeof(NTPpacket));
// ugly
return 0;
}

bool ICACHE_FLASH_ATTR NtpClient::processTime() {

timeStatus_t ts = timeStatus();

switch (ts) {
case timeNeedsSync:
case timeSet:
return true;
default:
//sync
now();
return false;
}
}

String ICACHE_FLASH_ATTR NtpClient::zeroPaddedIntVal(int val) {
if (val < 10)
return "0" + String(val);
else
return String(val);
}

//returns the current date/time as a string in iso8601 format
String ICACHE_FLASH_ATTR NtpClient::iso8601DateTime() {

String hyphen = "-";
String colon = ":";

return String(year()) + hyphen +
zeroPaddedIntVal(month()) + hyphen +
zeroPaddedIntVal(day()) + "T" +
zeroPaddedIntVal(hour()) + colon +
zeroPaddedIntVal(minute()) + colon +
zeroPaddedIntVal(second()) +
(timezone == 0 ? "Z" : String(timezone));
}

time_t NtpClient::getUptimeSec() {
_uptimesec = _uptimesec + (millis () - _uptimesec);
return _uptimesec / 1000;
}

deviceUptime ICACHE_FLASH_ATTR NtpClient::getDeviceUptime() {

unsigned long currentmillis = millis();

deviceUptime uptime;
uptime.secs = (long)((currentmillis / 1000) % 60);
uptime.mins = (long)((currentmillis / 60000) % 60);
uptime.hours = (long)((currentmillis / 3600000) % 24);
uptime.days = (long)((currentmillis / 86400000) % 10);

return uptime;

}

String ICACHE_FLASH_ATTR NtpClient::getDeviceUptimeString() {

deviceUptime uptime = getDeviceUptime();

return String(uptime.days) + " days, " +
String(uptime.hours) + " hours, " +
String(uptime.mins) + " mins, " +
String(uptime.secs) + " secs";

}

/*
* returns the current time as UTC (timezone offset removed)
*/
ICACHE_FLASH_ATTR time_t NtpClient::getUtcTimeNow() {

return now() - timezone;

}
54 changes: 54 additions & 0 deletions src/Ntp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* ntp.h
*
* Created on: 8 Mar 2016
* Author: joe
*/

#ifndef NTP_H_
#define NTP_H_

#include <ESP8266WiFi.h>
#include <ESPAsyncUDP.h>
#include <TimeLib.h>

#define NTP_PACKET_SIZE 48 // NTP time is in the first 48 bytes of message

struct deviceUptime {
long days;
long hours;
long mins;
long secs;
};

class NtpClient {
public:

void ICACHE_FLASH_ATTR Ntp(const char * server, int8_t tz, time_t syncSecs);
ICACHE_FLASH_ATTR virtual ~NtpClient();

static char * TimeServerName;
static IPAddress timeServer;
static int8_t timezone;
static time_t syncInterval;

static AsyncUDP udpListener;

static byte NTPpacket[NTP_PACKET_SIZE];

static ICACHE_FLASH_ATTR String iso8601DateTime();
static ICACHE_FLASH_ATTR deviceUptime getDeviceUptime();
static ICACHE_FLASH_ATTR String getDeviceUptimeString();
static ICACHE_FLASH_ATTR time_t getUtcTimeNow();
bool ICACHE_FLASH_ATTR processTime();
time_t getUptimeSec();

private:
static ICACHE_FLASH_ATTR String zeroPaddedIntVal(int val);
static ICACHE_FLASH_ATTR time_t getNtpTime();

protected:
time_t _uptimesec = 0;
};

#endif /* NTP_H_ */
4 changes: 0 additions & 4 deletions src/backup.htm.gz.h

This file was deleted.

Loading

0 comments on commit bc7e5bd

Please sign in to comment.