118 lines
2.5 KiB
C++
118 lines
2.5 KiB
C++
//=========================================================
|
|
// Header
|
|
//=========================================================
|
|
|
|
// Include Libraries And Headers
|
|
#include "WiFi.h"
|
|
#include "definitions.h"
|
|
#include "buttons.h"
|
|
#include "oled.h"
|
|
#include "wireless.h"
|
|
#include "time.h"
|
|
|
|
//=========================================================
|
|
// Initialization
|
|
//=========================================================
|
|
|
|
void setup() {
|
|
|
|
// Serial Data
|
|
Serial.begin(115200);
|
|
Serial.println();
|
|
|
|
btn_start(); // Start Button Function
|
|
oled_start(); // Starting OLED
|
|
oled_clear(); // Clear OLED Display
|
|
|
|
// btn_test(); // This Is For Test
|
|
// SPIFFS.format();
|
|
|
|
// Wait For Reset
|
|
wifi_wait_for_reset();
|
|
|
|
// Activate Buzzer Pin
|
|
pinMode(_motor_pin, OUTPUT);
|
|
|
|
buzz();
|
|
|
|
oled_logo(); // Display LOGO
|
|
|
|
// Print Seperator
|
|
Serial.println(MSG_SPACER);
|
|
|
|
LED_START; // Starting LED
|
|
LED_OFF; // Turn Off
|
|
wifi_start(); // WiFi Start
|
|
LED_ON; // WiFi Connected
|
|
|
|
// Print Seperator
|
|
Serial.println(MSG_SPACER);
|
|
|
|
// ESP Chip ID
|
|
uint32_t chipId = ESP.getChipId();
|
|
Serial.print("ESP Chip ID : "); Serial.println(chipId);
|
|
|
|
// ESP Device Address
|
|
Serial.print("ESP IP Address : "); Serial.println(WiFi.localIP());
|
|
|
|
// ESP MAC Address
|
|
String macAddress = WiFi.macAddress();
|
|
Serial.print("ESP MC Address : "); Serial.println(macAddress);
|
|
Serial.println(MSG_SPACER);
|
|
|
|
// NTP Function
|
|
ntp_begin();
|
|
ntp_update();
|
|
syncedMillisOffset = timeClient.getEpochTime() * 1000 - startMillis;
|
|
|
|
// Connected Server
|
|
oled_clear();
|
|
oled_text(1, 0, 0, "Connect To Server");
|
|
|
|
// Connect To Server
|
|
server_connect();
|
|
|
|
// Display Connected
|
|
oled_text(1, 0, 10, "Connection Success");
|
|
|
|
// Wait On Sec
|
|
delay(1000);
|
|
|
|
// Print Seperator
|
|
Serial.println(MSG_SPACER);
|
|
|
|
// New Timming
|
|
timing = millis();
|
|
|
|
}
|
|
|
|
//=========================================================
|
|
// Running Loop
|
|
//=========================================================
|
|
|
|
void loop() {
|
|
|
|
// Maintain Server Connection
|
|
server_connect();
|
|
|
|
// Update Time
|
|
ntp_update();
|
|
// ntp_sync_millis();
|
|
|
|
// Read Buttons With Actions
|
|
read_buttons();
|
|
|
|
// Send VIA Serial
|
|
send_via_serial();
|
|
|
|
// Read TCP Data
|
|
read_tcp();
|
|
|
|
// Send Keep Alive
|
|
send_keep_alive();
|
|
|
|
}
|
|
|
|
//=========================================================
|
|
// END
|
|
//=========================================================
|