mirror of
https://gitlab.com/fabinfra/fabhardware/fabpel.git
synced 2025-03-12 14:41:44 +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)
|
byte limit(byte value)
|
||||||
{
|
{
|
||||||
if(value > LIMIT)
|
return (LIMIT*value)/255;
|
||||||
{
|
|
||||||
return LIMIT;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_wifi()
|
void setup_wifi()
|
||||||
{
|
{
|
||||||
|
pixels.setPixelColor(0, pixels.Color(0, 0, LIMIT));
|
||||||
|
pixels.show();
|
||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
Serial.println("Connecting Wifi ...");
|
Serial.println("Connecting Wifi ...");
|
||||||
|
|
||||||
@ -245,6 +241,17 @@ void reconnect()
|
|||||||
{
|
{
|
||||||
while (!client.connected())
|
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 ...");
|
Serial.println("Connecting MQTT ...");
|
||||||
String clientId = "FABPEL-";
|
String clientId = "FABPEL-";
|
||||||
clientId += String(random(0xffff), HEX);
|
clientId += String(random(0xffff), HEX);
|
||||||
@ -282,14 +289,14 @@ void reconnect()
|
|||||||
|
|
||||||
char id[6] = "00000";
|
char id[6] = "00000";
|
||||||
sprintf(id, "%05d", FABPELID);
|
sprintf(id, "%05d", FABPELID);
|
||||||
mqtt->publish("fabpel", id);
|
client.publish("fabpel", id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.print("failed, rc=");
|
Serial.print("failed, rc=");
|
||||||
Serial.print(client.state());
|
Serial.print(client.state());
|
||||||
Serial.println(" try again in 5 seconds");
|
Serial.println(" try again in 5 seconds");
|
||||||
delay(5000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,15 +306,17 @@ void setup()
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
|
pixels.begin();
|
||||||
|
pixels.clear();
|
||||||
|
|
||||||
|
pixels.setPixelColor(0, pixels.Color(LIMIT, 0, 0));
|
||||||
|
pixels.show();
|
||||||
|
|
||||||
setup_wifi();
|
setup_wifi();
|
||||||
|
|
||||||
client.setServer(MQTT_BROKER, 1883);
|
client.setServer(MQTT_BROKER, 1883);
|
||||||
client.setCallback(callback);
|
client.setCallback(callback);
|
||||||
|
|
||||||
pixels.begin();
|
|
||||||
pixels.clear();
|
|
||||||
pixels.show();
|
|
||||||
|
|
||||||
pinMode(PIN_BUZZER, OUTPUT);
|
pinMode(PIN_BUZZER, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,6 +327,12 @@ void loop()
|
|||||||
if (!client.connected())
|
if (!client.connected())
|
||||||
{
|
{
|
||||||
reconnect();
|
reconnect();
|
||||||
|
pixels.setPixelColor(0, pixels.Color(0, LIMIT, 0));
|
||||||
|
pixels.show();
|
||||||
|
|
||||||
|
delay(500);
|
||||||
|
pixels.clear();
|
||||||
|
pixels.show();
|
||||||
}
|
}
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user