Commit 57e15823 authored by Andrea Trentini's avatar Andrea Trentini

tolto webota (fallito via tunnel, magari riprovare lì), aggiunta password OTA

parent 008025c6
......@@ -93,15 +93,15 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_DATA_PIN, NEO_GRB + NE
// TODO colori da provare, ora ho messo valori a occhio
// 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(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 C_UTENTI=strip.Color(10,10,100);
const uint32_t C_PRESTITI=strip.Color(0,100,100);
const uint32_t C_PRESTITI_OGGI=strip.Color(100,0,0);
const uint32_t C_UTENTI_PLUS=strip.Color(100,100,0);
const uint32_t C_UTENTI_ATTIVI=strip.Color(100,70,0);
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?
const uint32_t vuoto=strip.Color(50,50,50);
const uint32_t white=strip.Color(100,100,100);
const uint32_t violaCormano=strip.Color(53,12,106);
// WiFi
WiFiClient wifiClient;
......@@ -131,10 +131,11 @@ long lastMsg = 0;
#define MSG_LEN 150
char msg[MSG_LEN];
/*
#define WEBPORT 8080
ESP8266WebServer httpServer(WEBPORT);
ESP8266HTTPUpdateServer httpUpdater;
*/
......@@ -273,15 +274,18 @@ void setAll() {
}
*/
// TODO animare?
void bar(uint32_t col,int len) {
bar(col,violaCormano,len);
}
void bar(uint32_t col,uint32_t other_col,int len) {
for(int nr=0; nr<NUM_LEDS; nr++) {
if(nr<=len) {
setPixelColor(nr,col);
strip.show();
delay(STEP);
} else {
setPixelColor(nr,vuoto);
setPixelColor(nr,other_col);
strip.show();
}
......@@ -292,6 +296,7 @@ void bar(uint32_t col,int len) {
}
}
/*
void barFlash(uint32_t col,int len, int flashes) {
bar(col,len);
for(int c=0; c<flashes; c++) {
......@@ -304,6 +309,7 @@ void barFlash(uint32_t col,int len, int flashes) {
delay(MICROSTEP);
}
}
*/
void displayOne(int campo) {
int mapped=map(correnti[campo],minimi[campo],massimi[campo],0,NUM_LEDS);
......@@ -312,28 +318,18 @@ void displayOne(int campo) {
Serial.print(":");
Serial.println(mapped);
if(changed(campo)) barFlash(colori[campo],mapped,FLASHES);
else bar(colori[campo],mapped);
delay(BAR_DELAY);
}
void animate() {
/*
barFlash(CRGB::Red,2,FLASHES);
barFlash(CRGB::Blue,0,FLASHES);
barFlash(CRGB::Yellow,3,FLASHES);
barFlash(CRGB::Magenta,NUM_LEDS-1,FLASHES);
if(changed(campo))
barFlash(colori[campo],mapped,FLASHES);
else
*/
bar(colori[campo],mapped);
displayOne(2);
//delay(BAR_DELAY);
}
/*
for(int campo=0; campo<NUMCAMPI; campo++) {
//if(changed(campo))
displayOne(campo);
}
*/
void show() {
displayOne(2); // campo 2, prestiti_oggi
}
void mqtt_callback(char* topic, byte* payload, unsigned int length) {
......@@ -346,7 +342,7 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
}
*/
Serial.println();
strip.clear();
if(payload[0]=='O')
......@@ -355,7 +351,7 @@ void mqtt_callback(char* topic, byte* payload, unsigned int length) {
if(payload[0]=='I')
impulseDown(white);
displayOne(2);
show();
}
void mqtt_reconnect() {
......@@ -404,7 +400,7 @@ void mqtt_setup() {
boolean wifi_setup() {
WiFi.mode(WIFI_STA);
WiFi.hostname("BiblioVisualizer");
WiFi.hostname(TOPIC);
// We start by connecting to a WiFi network
Serial.print("=== Connecting to: ");
......@@ -413,10 +409,10 @@ boolean wifi_setup() {
WiFi.disconnect();
WiFi.begin(ssid.c_str(), password.c_str());
strip.clear();
strip.clear();
for (int i=0;
(WiFi.status() != WL_CONNECTED) && (i < WIFI_TENTATIVI) && digitalRead(0)==HIGH;
i++) {
(WiFi.status() != WL_CONNECTED) && (i < WIFI_TENTATIVI) && digitalRead(0)==HIGH;
i++) {
delay(100);
Serial.print(".");
bar(strip.Color(0,100,0),i);
......@@ -440,10 +436,10 @@ boolean wifi_setup() {
ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
// ArduinoOTA.setHostname("myesp8266");
ArduinoOTA.setHostname(TOPIC);
// No authentication by default
// ArduinoOTA.setPassword((const char *)"123");
ArduinoOTA.setPassword((const char *)"barra");
ArduinoOTA.onStart([]() {
Serial.println("OTA Start");
......@@ -469,13 +465,13 @@ boolean wifi_setup() {
ArduinoOTA.begin();
Serial.println("+++ OTA Ready");
/*
MDNS.begin(TOPIC);
httpUpdater.setup(&httpServer);
httpServer.begin();
MDNS.addService("http", "tcp", WEBPORT);
Serial.println("+++ WebOTA Ready");
*/
return true;
} else {
......@@ -490,13 +486,13 @@ boolean wifi_setup() {
Scheduler runner;
Task taskGetAndShow(TASK_MINUTE, TASK_FOREVER, []() {
Task taskGetAndShow(2*TASK_MINUTE, TASK_FOREVER, []() {
Serial.println("Connecting...");
if(WiFi.status() != WL_CONNECTED) wifi_setup();
// Connect to HTTP server
wifiClient.setTimeout(10000);
wifiClient.setTimeout(5000);
if (!wifiClient.connect("frassino.comperio.it", 80)) {
Serial.println("Connection failed");
return;
......@@ -556,16 +552,16 @@ Task taskGetAndShow(TASK_MINUTE, TASK_FOREVER, []() {
// print status
printAll();
// show
animate();
show();
});
/** visualizzare qualcosa ogni secondo?
*/
/** visualizzare qualcosa ogni secondo... */
int current=0;
Task taskSeconds(TASK_SECOND, TASK_FOREVER,[]() {
/*
Serial.print(current);
Serial.print(" ");
*/
uint32_t prev=getPixelColor(current);
setPixelColor(current,strip.Color(0,0,250));
......@@ -574,7 +570,6 @@ Task taskSeconds(TASK_SECOND, TASK_FOREVER,[]() {
current--;
if(current>=NUM_LEDS) current=0;
if(current<0) current=NUM_LEDS-1;
//animate();
});
/** per avere un feedback di funzionamento anche via mqtt */
......@@ -615,6 +610,8 @@ void setup() {
wifi_setup();
mqtt_setup();
delay(5000);
// Tasks
runner.init();
......@@ -639,6 +636,6 @@ void setup() {
void loop() {
runner.execute();
ArduinoOTA.handle();
httpServer.handleClient(); // WebOTA
//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