|
|
|
@ -3,12 +3,15 @@ |
|
|
|
|
#include <ESP8266WiFi.h> |
|
|
|
|
#include <ESP8266HTTPClient.h> |
|
|
|
|
#include <EEPROM.h> |
|
|
|
|
#include <Ticker.h> |
|
|
|
|
|
|
|
|
|
const char* WIFI_SSID = "tanner"; |
|
|
|
|
const char* WIFI_PASS = "point cloud truck dust swim army"; |
|
|
|
|
const char* WIFI_SSID = "Protospace"; |
|
|
|
|
const char* WIFI_PASS = "yycmakers"; |
|
|
|
|
char wifiMACAddr[18]; |
|
|
|
|
const String SOCKET_URL = String("http://192.168.1.9:8080/api/lockout/"); |
|
|
|
|
const String CARD_URL = String("http://192.168.1.9:8000/cards/"); |
|
|
|
|
const String SOCKET_URL = String("http://tools-socket.protospace.ca/api/lockout/"); |
|
|
|
|
const String CARD_URL = String("http://tools-auth.protospace.ca/cards/"); |
|
|
|
|
|
|
|
|
|
Ticker ticker; |
|
|
|
|
|
|
|
|
|
#define CARD_BUFFER_LENGTH 14 |
|
|
|
|
char cardBuffer[CARD_BUFFER_LENGTH]; |
|
|
|
@ -39,7 +42,7 @@ typedef struct __attribute__((packed)) cardData { |
|
|
|
|
|
|
|
|
|
#define DELAY_TIME 10 |
|
|
|
|
#define COMM_LOCK_IDLE_TIME 50 |
|
|
|
|
#define COMM_CARD_IDLE_TIME 200 |
|
|
|
|
#define COMM_CARD_IDLE_TIME 1000 |
|
|
|
|
|
|
|
|
|
#define EEPROM_SIZE 4095 |
|
|
|
|
#define EEPROM_START 0 |
|
|
|
@ -80,13 +83,14 @@ void setup() |
|
|
|
|
pinMode(RED_LED_PIN, OUTPUT); |
|
|
|
|
|
|
|
|
|
EEPROM.begin(EEPROM_SIZE); |
|
|
|
|
|
|
|
|
|
ticker.attach_ms(DELAY_TIME, tickerLoop); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void loop() |
|
|
|
|
// The stuff in this loop must not be blocked by network delay
|
|
|
|
|
void tickerLoop() |
|
|
|
|
{ |
|
|
|
|
processWifiState(); |
|
|
|
|
processLockState(); |
|
|
|
|
processCommState(); |
|
|
|
|
|
|
|
|
|
if (Serial.available() >= CARD_BUFFER_LENGTH) { |
|
|
|
|
uint8_t bufPos = 0; |
|
|
|
@ -107,11 +111,17 @@ void loop() |
|
|
|
|
cardBuffer[bufPos++] = readChar; |
|
|
|
|
|
|
|
|
|
if (readChar == 0x3 && bufPos == CARD_BUFFER_LENGTH) { |
|
|
|
|
checkCard(); |
|
|
|
|
if (lockState == LOCK_OFF) checkCard(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void loop() |
|
|
|
|
{ |
|
|
|
|
processWifiState(); |
|
|
|
|
processCommState(); |
|
|
|
|
|
|
|
|
|
delay(DELAY_TIME); |
|
|
|
|
} |
|
|
|
@ -346,7 +356,7 @@ void processCommState() |
|
|
|
|
if (LOGGING) Serial.print("[INFO] HTTP POST: "); |
|
|
|
|
String postData = serializeLockJson(lockState); |
|
|
|
|
if (LOGGING) Serial.println(postData); |
|
|
|
|
uint16_t lockHTTPCode = lockHTTP.POST(postData); |
|
|
|
|
int16_t lockHTTPCode = lockHTTP.POST(postData); |
|
|
|
|
|
|
|
|
|
if (lockHTTPCode > 0) { |
|
|
|
|
if (LOGGING) Serial.printf("[INFO] POST success, code: %d\n", lockHTTPCode); |
|
|
|
@ -385,7 +395,7 @@ void processCommState() |
|
|
|
|
cardHTTP.addHeader("Content-Type", "application/json"); |
|
|
|
|
|
|
|
|
|
if (LOGGING) Serial.println("[INFO] HTTP GET"); |
|
|
|
|
uint16_t cardHTTPCode = cardHTTP.GET(); |
|
|
|
|
int16_t cardHTTPCode = cardHTTP.GET(); |
|
|
|
|
|
|
|
|
|
if (cardHTTPCode > 0) { |
|
|
|
|
if (LOGGING) Serial.printf("[INFO] GET success, code: %d\n", cardHTTPCode); |
|
|
|
|