#include <DNSServer.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> #define OUTLET_1 D3 #define OUTLET_2 D1 static const uint8_t D1 = 5; static const uint8_t D3 = 0; static const char *DNS_NAME = "esp8266"; static const char *AP_NAME = "ESP8266 Smart Outlet"; static const char *AP_PASS = "******"; static const unsigned long SERIAL_DEBUG_BAUD= 115200; WebSocketsServer ws = WebSocketsServer(81); void turnOn(uint8_t outlet) { pinMode(outlet, HIGH); } void turnOff(uint8_t outlet) { pinMode(outlet, LOW); } void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length){ switch(type) { case WStype_DISCONNECTED: Serial.println("Websocket Disconnected..."); break;
int ch1en = -1, ch2en = -1, ch3en = -1, ch4en = -1; time_t ch1start = 0, ch1end = 0, ch1rest = 0; time_t ch2start = 0, ch2end = 0, ch2rest = 0; time_t ch3start = 0, ch3end = 0, ch3rest = 0; time_t ch4start = 0, ch4end = 0, ch4rest = 0; #ifndef _MINI ESP8266WebServer httpd(80); //Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); #endif Adafruit_ADS1115 ads; WiFiClient espClient; PubSubClient mqtt(espClient); OneWire oneWire; DallasTemperature ds18b20 = NULL; WebSocketsServer webSocket = WebSocketsServer(81); ESP8266WiFiMulti wifiMulti; PCA9633 rgbw; // instance of pca9633 library /* Don't hardwire the IP address or we won't get the benefits of the pool. * Lookup the IP address for the host name instead */ IPAddress timeServerIP; // time.nist.gov NTP server address unsigned int localPort = 2390; // local port to listen for UDP packets const char* ntpServerName = "us.pool.ntp.org"; const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets // A UDP instance to let us send and receive packets over UDP WiFiUDP udp; void i2c_wordwrite(int address, int cmd, int theWord) {
#include "Arduino.h" #include "Wifi.h" #define NETWORKNAME "tinkerbox" #define NETWORKPASS "faceface01" ESP8266WiFiMulti WiFiMulti; ESP8266WebServer server = ESP8266WebServer(80); WebSocketsServer webSocket = WebSocketsServer(8899); Wifi::Wifi(){ } void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { switch(type) { case WStype_DISCONNECTED: USE_SERIAL.printf("[%u] Disconnected!\n", num); break; case WStype_CONNECTED: { IPAddress ip = webSocket.remoteIP(num); USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload); // send message to client webSocket.sendTXT(num, "Connected"); } break; case WStype_TEXT: USE_SERIAL.printf("[%u] Message: %s\n", num, payload);