Commit 008025c6 authored by Andrea Trentini's avatar Andrea Trentini

con flash per I/U del contapersone, provato, sembra ok

parent 36f7e03b
......@@ -95,15 +95,14 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_DATA_PIN, NEO_GRB + NE
// https://en.wikipedia.org/wiki/RGB_color_model
const uint32_t C_UTENTI=strip.Color(10,10,100); // CRGB::Cyan
const uint32_t C_PRESTITI=strip.Color(0,100,100); // CRGB::Yellow
const uint32_t C_PRESTITI_OGGI=strip.Color(150,0,0); // era CRGB::Blue
const uint32_t C_PRESTITI_OGGI=strip.Color(100,0,0); // era CRGB::Blue
const uint32_t C_UTENTI_PLUS=strip.Color(150,150,0); // CRGB::Brown
const uint32_t C_UTENTI_ATTIVI=strip.Color(150,100,0); // CRGB::Magenta
const uint32_t colori[]= {C_UTENTI,C_PRESTITI,C_PRESTITI_OGGI,C_UTENTI_PLUS,C_UTENTI_ATTIVI};
const uint32_t vuoto=strip.Color(80,80,80); // CRGB::Red; // TODO: bianco o spento?
const uint32_t white=strip.Color(255,255,255);
//CRGB vuoto=CRGB::White; // TODO: bianco o spento?
// WiFi
WiFiClient wifiClient;
IPAddress gateway;
......@@ -241,7 +240,7 @@ void setPixelColor(uint16_t n, uint32_t c) {
strip.setPixelColor(ledIndex(n), c);
}
void impulseDown(uint32_t col) {
void impulseUp(uint32_t col) {
for(int nr=0; nr<NUM_LEDS; nr++) {
uint32_t prec=getPixelColor(nr);
setPixelColor(nr,col);
......@@ -252,7 +251,7 @@ void impulseDown(uint32_t col) {
}
}
void impulseUp(uint32_t col) {
void impulseDown(uint32_t col) {
for(int nr=NUM_LEDS-1; nr>=0; nr--) {
uint32_t prec=getPixelColor(nr);
setPixelColor(nr,col);
......@@ -341,18 +340,22 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
/*
for (int i=0; i<length; i++) {
Serial.print((char)payload[i]);
}
*/
Serial.println();
strip.clear();
if(payload[0]=='O')
impulseUp(strip.Color(0,100,100));
impulseUp(white);
if(payload[0]=='I')
impulseDown(strip.Color(100,0,100));
impulseDown(white);
impulseUp(strip.Color(0,0,100)); // per vedere se callback viene chiamata
displayOne(2);
}
void mqtt_reconnect() {
......@@ -389,8 +392,7 @@ void mqtt_send(String topic,String payload) {
void mqtt_subscribe() {
Serial.print("subscribing: ");
Serial.println(mqtt_client.subscribe("#/in-out")); // TODO parametrizzare/config
Serial.println(mqtt_client.subscribe("ContaPersoneTesting/in-out")); // NB non gestisce wildcard!!!
}
void mqtt_setup() {
......@@ -401,8 +403,6 @@ void mqtt_setup() {
}
boolean wifi_setup() {
delay(500);
WiFi.mode(WIFI_STA);
WiFi.hostname("BiblioVisualizer");
......@@ -413,9 +413,13 @@ boolean wifi_setup() {
WiFi.disconnect();
WiFi.begin(ssid.c_str(), password.c_str());
for (int i=0; (WiFi.status() != WL_CONNECTED) && (i < WIFI_TENTATIVI) && digitalRead(0)==HIGH; i++) {
delay(500);
strip.clear();
for (int i=0;
(WiFi.status() != WL_CONNECTED) && (i < WIFI_TENTATIVI) && digitalRead(0)==HIGH;
i++) {
delay(100);
Serial.print(".");
bar(strip.Color(0,100,0),i);
}
if(WiFi.status() == WL_CONNECTED) {
......@@ -448,8 +452,10 @@ boolean wifi_setup() {
Serial.println("OTA End");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
bar(strip.Color(0,0,200),ledIndex(NUM_LEDS*progress/total));
//Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
int level=ledIndex(NUM_LEDS*progress/total);
if(level%10==0)
bar(strip.Color(0,0,200),level);
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("OTA Error[%u]: ", error);
......@@ -486,6 +492,8 @@ Scheduler runner;
Task taskGetAndShow(TASK_MINUTE, TASK_FOREVER, []() {
Serial.println("Connecting...");
if(WiFi.status() != WL_CONNECTED) wifi_setup();
// Connect to HTTP server
wifiClient.setTimeout(10000);
......@@ -577,11 +585,6 @@ Task taskMqtt(10*TASK_MINUTE, TASK_FOREVER, []() {
// TODO: mandare anche uno status sui dati biblio?
});
/** va chiamato per il subscribe, altrimenti non lo gestisce */
Task taskMqttSub(TASK_SECOND, TASK_FOREVER, []() {
mqtt_client.loop();
});
/** per buttar fuori qualcosa e vedere se va, controlla anche wifi */
Task taskStatus(20*TASK_MINUTE, TASK_FOREVER, []() {
impulseUp(strip.Color(200,200,0)); // TODO yellow? portare in define
......@@ -608,9 +611,9 @@ void setup() {
Serial.println("booting...");
// vari setup
led_setup();
wifi_setup();
mqtt_setup();
led_setup();
// Tasks
runner.init();
......@@ -628,10 +631,14 @@ void setup() {
taskSeconds.enable();
Serial.println("booted!");
for(int i=0; i<3; i++)
impulseUp(strip.Color(15,70,100));
}
void loop() {
runner.execute();
ArduinoOTA.handle();
httpServer.handleClient(); // WebOTA
if(!mqtt_client.loop()) mqtt_reconnect();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment