mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
|
|
#include <DNSServer.h>
|
|
#include <ESP8266WebServer.h>
|
|
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
|
|
#define button 12 // Pin for the button
|
|
#define led 14 //Pin for the notificationLed
|
|
WiFiManager wifiManager;
|
|
String text="{\"id\": \"1\", \"method\": \"toggle\", \"params\":[]}\r\n"; // Function for toggle the light
|
|
const char* H0 = "192.168.0.21"; // Ip from first light
|
|
int port =55443; // Lights port
|
|
void setup() {
|
|
pinMode(led, OUTPUT);
|
|
digitalWrite(led, LOW);
|
|
pinMode(button, INPUT);
|
|
Serial.begin(115200);
|
|
wifiManager.setConfigPortalTimeout(180);
|
|
wifiManager.autoConnect("LightSwitch");
|
|
Serial.println("Started!");
|
|
digitalWrite(led, HIGH);
|
|
}
|
|
void loop() {
|
|
|
|
delay(5000);
|
|
Serial.println("test");
|
|
SendInfo();
|
|
|
|
}
|
|
void SendInfo(){
|
|
// Use WiFiClient class to create TCP connections
|
|
digitalWrite(led, LOW);
|
|
WiFiClient client;
|
|
client.connect(H0,port);
|
|
client.print(text);
|
|
client.stop();
|
|
digitalWrite(led, HIGH);
|
|
}
|
|
void OnDemandConfig(){
|
|
wifiManager.setConfigPortalTimeout(180); //Startuva WiFi vo AP i moze da se prekonfigurira WIFI-ot i novite informacii ke se zacuvaat vo EEPROM.
|
|
wifiManager.startConfigPortal("LightSwitch"); // Se pushta so ime SmartPost
|
|
}
|