2020-02-12 00:37:09 +00:00
|
|
|
#include <ArduinoJson.h>
|
|
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
#include <ESP8266WiFi.h>
|
|
|
|
#include <ESP8266HTTPClient.h>
|
|
|
|
|
|
|
|
|
2020-02-17 01:41:13 +00:00
|
|
|
#define OWN_PIN 28
|
|
|
|
#define FREE_CYCLES 10
|
2020-02-12 00:37:09 +00:00
|
|
|
#define PIN 2
|
2020-02-17 01:41:13 +00:00
|
|
|
#define NUMPIXELS 58
|
2020-02-12 00:37:09 +00:00
|
|
|
const char* ssid = "CTDO-LEGACY";
|
2020-02-17 01:41:13 +00:00
|
|
|
const char* password = "****";
|
2022-01-11 12:19:47 +00:00
|
|
|
const char* apiEndpoint = "http://spacepanel-aggregator-ingress.ctdo-spacepanel.195.160.168.3.nip.io/leds";
|
2020-02-12 00:37:09 +00:00
|
|
|
const int pollInterval = 10000;
|
|
|
|
HTTPClient http;
|
|
|
|
|
|
|
|
|
2020-02-17 01:41:13 +00:00
|
|
|
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
|
2020-02-12 00:37:09 +00:00
|
|
|
|
|
|
|
int delayval = 500;
|
2020-02-17 01:41:13 +00:00
|
|
|
int freecycles = 0;
|
2020-02-12 00:37:09 +00:00
|
|
|
|
|
|
|
void setLED(int i, String value) {
|
|
|
|
String value_short = value.substring(1);
|
|
|
|
char charbuf[8];
|
|
|
|
value_short.toCharArray(charbuf,8);
|
|
|
|
long int rgb = strtol(charbuf,0,16); //=>rgb=0x001234FE;
|
|
|
|
byte r=(byte)(rgb>>16);
|
|
|
|
byte g=(byte)(rgb>>8);
|
|
|
|
byte b=(byte)(rgb);
|
|
|
|
|
|
|
|
Serial.print(value_short);
|
|
|
|
Serial.print("-> ");
|
|
|
|
Serial.print(r);
|
|
|
|
Serial.print(", ");
|
|
|
|
Serial.print(g);
|
|
|
|
Serial.print(", ");
|
|
|
|
Serial.println(b);
|
2020-02-17 01:41:13 +00:00
|
|
|
pixels.setPixelColor(i, pixels.Color(r/25,g/25,b/25));
|
2020-02-12 00:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
WiFi.begin(ssid, password);
|
|
|
|
Serial.println(WiFi.macAddress());
|
|
|
|
while (WiFi.status() != WL_CONNECTED) {
|
|
|
|
delay(1000);
|
|
|
|
Serial.println("Connecting...");
|
|
|
|
}
|
|
|
|
Serial.println("Connected.");
|
|
|
|
|
|
|
|
pixels.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
Serial.println("Sending request...");
|
|
|
|
http.begin(apiEndpoint);
|
|
|
|
int httpCode = http.GET();
|
|
|
|
Serial.println("Success.");
|
|
|
|
if (httpCode == 200) {
|
|
|
|
String json = http.getString();
|
|
|
|
const size_t capacity = JSON_ARRAY_SIZE(NUMPIXELS) + 510;
|
|
|
|
DynamicJsonDocument doc(capacity);
|
|
|
|
deserializeJson(doc, json);
|
|
|
|
for (int i = 0; i < NUMPIXELS; i++) {
|
2020-02-17 01:41:13 +00:00
|
|
|
if (i == OWN_PIN && freecycles < FREE_CYCLES) {
|
|
|
|
setLED(i, "#00ff00");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Serial.print("LED" + String(i) + ": ");
|
|
|
|
const char* element = doc[i];
|
|
|
|
String value = String(element);
|
|
|
|
setLED(i, value);
|
|
|
|
Serial.print("LED" );
|
|
|
|
Serial.print(i);
|
|
|
|
Serial.print("Color: ");
|
|
|
|
Serial.println(value);
|
|
|
|
}
|
2020-02-12 00:37:09 +00:00
|
|
|
|
|
|
|
}
|
2020-02-17 01:41:13 +00:00
|
|
|
pixels.show();
|
|
|
|
freecycles++;
|
2020-02-12 00:37:09 +00:00
|
|
|
} else {
|
|
|
|
Serial.println("Error: Statuscode" + httpCode);
|
|
|
|
}
|
|
|
|
delay(pollInterval);
|
|
|
|
}
|