// remote egg status
// vgmlr
#include "ESP8266WiFi.h"
#include "ESP8266HTTPClient.h"
#include "WiFiClient.h"
// set local
const char* ssid = "yourwifi";
const char* password = "password";
// set get url
// http unless certificate finger-print
// text shd be 000000000 format (rgb)
const char* dest = "http://yourdomain.com/egg.txt";
WiFiClient WifiClient;
#include "FastLED.h"
#define NLEDS 24
#define LTYPE WS2812B
#define CORDER GRB
CRGB leds[NLEDS];
const int neo_pin = D6;
const long minutes = 30;
const long hold = (minutes * 60 * 1000);
int txtvalue;
String eggvalue;
void n_one (int r, int g, int b) {
leds[0] = CRGB (r,g,b);
FastLED.show();
}
void n_fade (int r, int g, int b) {
for (int v = 0; v < NLEDS; v++) {
leds[v] = CRGB (r,g,b);
FastLED.show();
delay(100);
}
}
void n_show (int r, int g, int b) {
for (int v = 0; v < NLEDS; v++) {
leds[v] = CRGB (r,g,b);
FastLED.show();
}
}
void setup() {
Serial.begin(115200);
FastLED.addLeds< LTYPE, neo_pin, CORDER >(leds, NLEDS).setCorrection(TypicalLEDStrip);
n_show(0, 0, 0); // clear
// load notification
n_fade(255, 0, 255);
delay(10);
n_fade(0, 0, 0);
delay(10);
n_show(0, 0, 0);
}
void loop() {
// run get
get_status();
// parse and convert to int
int red = eggvalue.substring(0, 3).toInt();
int green = eggvalue.substring(3, 6).toInt();
int blue = eggvalue.substring(6).toInt();
// send to fastled
n_fade(red, green, blue);
n_show(red, green, blue);
// wait for next get
delay(hold);
}
void get_status () {
WiFi.mode(WIFI_STA);
delay(100);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
n_one(255, 0, 0);
delay(500);
n_one(0, 0, 0);
delay(500);
}
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(WifiClient, dest);
txtvalue = http.GET();
if (txtvalue == HTTP_CODE_OK) {
eggvalue = http.getString();
}
http.end();
}
delay(500);
WiFi.mode(WIFI_OFF);
}