mirror of
https://gitlab.com/fabinfra/fabhardware/fabpel.git
synced 2025-03-11 22:21:45 +01:00
Boot State on first LED
This commit is contained in:
parent
72bfe406ce
commit
600bf99423
@ -43,18 +43,14 @@ int direction_pulse = 0;
|
||||
|
||||
byte limit(byte value)
|
||||
{
|
||||
if(value > LIMIT)
|
||||
{
|
||||
return LIMIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return (LIMIT*value)/255;
|
||||
}
|
||||
|
||||
void setup_wifi()
|
||||
{
|
||||
pixels.setPixelColor(0, pixels.Color(0, 0, LIMIT));
|
||||
pixels.show();
|
||||
|
||||
delay(10);
|
||||
Serial.println("Connecting Wifi ...");
|
||||
|
||||
@ -245,6 +241,17 @@ void reconnect()
|
||||
{
|
||||
while (!client.connected())
|
||||
{
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
pixels.setPixelColor(0, pixels.Color(0, 0, LIMIT));
|
||||
pixels.show();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
||||
pixels.setPixelColor(0, pixels.Color(LIMIT, 0, LIMIT));
|
||||
pixels.show();
|
||||
|
||||
Serial.println("Connecting MQTT ...");
|
||||
String clientId = "FABPEL-";
|
||||
clientId += String(random(0xffff), HEX);
|
||||
@ -282,14 +289,14 @@ void reconnect()
|
||||
|
||||
char id[6] = "00000";
|
||||
sprintf(id, "%05d", FABPELID);
|
||||
mqtt->publish("fabpel", id);
|
||||
client.publish("fabpel", id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(client.state());
|
||||
Serial.println(" try again in 5 seconds");
|
||||
delay(5000);
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -299,15 +306,17 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
|
||||
pixels.begin();
|
||||
pixels.clear();
|
||||
|
||||
pixels.setPixelColor(0, pixels.Color(LIMIT, 0, 0));
|
||||
pixels.show();
|
||||
|
||||
setup_wifi();
|
||||
|
||||
client.setServer(MQTT_BROKER, 1883);
|
||||
client.setCallback(callback);
|
||||
|
||||
pixels.begin();
|
||||
pixels.clear();
|
||||
pixels.show();
|
||||
|
||||
pinMode(PIN_BUZZER, OUTPUT);
|
||||
}
|
||||
|
||||
@ -318,6 +327,12 @@ void loop()
|
||||
if (!client.connected())
|
||||
{
|
||||
reconnect();
|
||||
pixels.setPixelColor(0, pixels.Color(0, LIMIT, 0));
|
||||
pixels.show();
|
||||
|
||||
delay(500);
|
||||
pixels.clear();
|
||||
pixels.show();
|
||||
}
|
||||
client.loop();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user