Pith - nodemcu_egg_status
nodemcu_egg_status/nodemcu_egg_status.ino [1.9 kb]
Modified: 18:17:52 58 026 (16 May 026)
14 Days Ago
// 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);
}
Updates
Shim - Android 70.026.1
Wedge - Linux 68.026.1
Wedge - Android 68.026.1
Taper - Linux 64.026.1
Ayh Extension - Chrome 63.026.1
Dev
TVShow (227) 'CSA'
TVShow (228) 'APT'
TVProgram (83) 'BXT'
Miter Update(s)
Shim (Dictation)

Menu
Calendar
Project Tin (024/029)
Miter
RSS Feed
User Avatar
@vgmlr
=SUM(parts)