Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch informations from other services
- Loading branch information
Showing
16 changed files
with
439 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
jenkins: | ||
url: "http://" | ||
topic: 'build' | ||
url: "" | ||
password: "" | ||
user: "" | ||
jobs: | ||
- job_name | ||
- proj | ||
|
||
coffee: | ||
endpoint: 'https://api.thingspeak.com/channels/125608/fields/1.json?sum=daily&timezone=Europe/Warsaw&days=1' | ||
topic: 'coffee' | ||
|
||
lunching: | ||
endpoint: 'https://api.lunching.pl/api/account/order-list' | ||
topic: 'food' | ||
username: '' | ||
password: '' | ||
|
||
mqtt: | ||
host: '' | ||
username: '' | ||
password: '' | ||
port: | ||
port: 0 | ||
|
||
topics: | ||
jenkins_status: 'build' | ||
button: 'button' | ||
presence: 'presence' | ||
button: | ||
topic: 'button' | ||
recipient: 0 | ||
messages: | ||
- "." | ||
- ".." | ||
|
||
hipchat: | ||
topic: 'presence' | ||
token: '' | ||
team: | ||
- email@gmail.com | ||
- email22gmail.com | ||
button_action: | ||
recipient: email@gmail.com | ||
messages: | ||
- "." | ||
- "Jeże" | ||
- emails@gmail.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
int buttonAccumulator = 0; | ||
boolean actionButtonPressed() { | ||
int actionButtonState = digitalRead(PIN_ACTION_BUTTON); | ||
|
||
if (actionButtonState == HIGH) { | ||
return false; | ||
} | ||
|
||
digitalWrite(PIN_STATUS_LED, HIGH); | ||
int buttonAccumulator = 0; | ||
while(actionButtonState == LOW) { | ||
delay(100); | ||
buttonAccumulator += 1; | ||
actionButtonState = digitalRead(PIN_ACTION_BUTTON); | ||
} | ||
digitalWrite(PIN_STATUS_LED, LOW); | ||
|
||
return buttonAccumulator >= 5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
void printWifiInfo() { | ||
Serial.println(""); | ||
Serial.println("WiFi connected"); | ||
Serial.println("IP address: "); | ||
Serial.println(WiFi.localIP()); | ||
} | ||
|
||
void setupOTA() { | ||
Serial.println("Configuring ArduinoOTA"); | ||
ArduinoOTA.setPort(OTA_PORT); | ||
ArduinoOTA.setHostname(OTA_HOST); | ||
ArduinoOTA.setPassword(OTA_PASSWORD); | ||
|
||
ArduinoOTA.onStart([]() { | ||
Serial.println("Starting"); | ||
}); | ||
ArduinoOTA.onEnd([]() { | ||
Serial.println("\nEnd"); | ||
}); | ||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { | ||
Serial.printf("Progress: %u%%\r", (progress / (total / 100))); | ||
}); | ||
ArduinoOTA.onError([](ota_error_t error) { | ||
Serial.printf("Error[%u]: ", error); | ||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); | ||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); | ||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); | ||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); | ||
else if (error == OTA_END_ERROR) Serial.println("End Failed"); | ||
}); | ||
|
||
ArduinoOTA.begin(); | ||
} | ||
|
||
void setupWifi() { | ||
delay(1000); | ||
Serial.println("----------"); | ||
Serial.println("Connecting to: "); | ||
Serial.println(WIFI_NAME); | ||
WiFi.mode(WIFI_STA); | ||
|
||
while (WiFi.waitForConnectResult() != WL_CONNECTED){ | ||
Serial.print("."); | ||
WiFi.begin(WIFI_NAME, WIFI_PASSWORD); | ||
|
||
delay(500); | ||
} | ||
Serial.println("OK!"); | ||
randomSeed(micros()); | ||
printWifiInfo(); | ||
setupOTA(); | ||
} | ||
|
||
void ensureWifiConnection() { | ||
if (WiFi.status() != WL_CONNECTED) { | ||
delay(1); | ||
Serial.print("WIFI Disconnected. Attempting reconnection."); | ||
setupWifi(); | ||
} | ||
} | ||
|
||
bool ensureMqttConnection() { | ||
ensureWifiConnection(); | ||
while (!client.connected()) { | ||
delay(1000); | ||
Serial.println("Attempting MQTT connection..."); | ||
// Create a random client ID | ||
String clientId = "lam.py-"; | ||
clientId += String(random(0xffff), HEX); | ||
Serial.print("Client id: "); | ||
Serial.println(clientId); | ||
if (client.connect(clientId.c_str(), MQTT_USER, MQTT_PASSWORD)) { | ||
printWifiInfo(); | ||
return true; | ||
} else { | ||
Serial.print("failed, rc="); | ||
Serial.print(client.state()); | ||
Serial.println(" try again in 5 seconds"); | ||
// Wait 5 seconds before retrying | ||
delay(5000); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void onConnect() { | ||
Serial.print("Subscribing: "); | ||
Serial.println(MQTT_TOPIC_BUILD); | ||
client.subscribe(MQTT_TOPIC_BUILD); | ||
Serial.println(MQTT_TOPIC_PRESENCE); | ||
client.subscribe(MQTT_TOPIC_PRESENCE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
byte defaultBrightness = 0; | ||
void colorWipe(uint32_t c, uint8_t wait) { | ||
strip.setBrightness(defaultBrightness); | ||
for(uint16_t i=0; i<strip.numPixels(); i++) { | ||
strip.setPixelColor(i, c); | ||
strip.show(); | ||
delay(wait); | ||
} | ||
} | ||
|
||
//Theatre-style crawling lights. | ||
void theaterChase(uint32_t c, uint8_t wait) { | ||
strip.setBrightness(defaultBrightness); | ||
for (int j=0; j<10; j++) { //do 10 cycles of chasing | ||
for (int q=0; q < 3; q++) { | ||
for (uint16_t i=0; i < strip.numPixels(); i=i+3) { | ||
strip.setPixelColor(i+q, c); //turn every third pixel on | ||
} | ||
strip.show(); | ||
|
||
delay(wait); | ||
|
||
for (uint16_t i=0; i < strip.numPixels(); i=i+3) { | ||
strip.setPixelColor(i+q, 0); //turn every third pixel off | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.