forked from jeanjack/PiedThon
Compare commits
No commits in common. "a9174a59b84acd9f2d32e908e558622eef31824b" and "c39d0fb24f154d5ad066c3ab3d16b3a4d9a1469e" have entirely different histories.
a9174a59b8
...
c39d0fb24f
@ -1,5 +1,3 @@
|
|||||||
# PiedThon
|
# PiedThon
|
||||||
|
|
||||||
Feux PiedThon ESP8266
|
Feux PiedThon ESP8266
|
||||||
|
|
||||||
https://wiki.fuz.re/doku.php?id=projets:fuz:piedthon
|
|
60
arduino.cpp
60
arduino.cpp
@ -1,15 +1,12 @@
|
|||||||
|
|
||||||
/***
|
/***
|
||||||
Fuz Piedthon
|
* Fuz Piedthon
|
||||||
Pedestrian traffic lights, green and red, controlled over MQTT
|
* Pedestrian traffic lights, green and red, controlled over MQTT
|
||||||
Board: ESP8266
|
* Board: ESP8266
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266mDNS.h>
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
#include <ArduinoOTA.h>
|
|
||||||
|
|
||||||
/// Pins configuration
|
/// Pins configuration
|
||||||
|
|
||||||
@ -21,7 +18,7 @@
|
|||||||
#define MQTT_SERVER "sonic.fuz.re"
|
#define MQTT_SERVER "sonic.fuz.re"
|
||||||
#define MQTT_SERVERPORT 1883
|
#define MQTT_SERVERPORT 1883
|
||||||
|
|
||||||
#define ESP_HOSTNAME "piedthon"
|
|
||||||
|
|
||||||
#include "WifiCredFuz.cpp" // Wifi and MQTT Credentials
|
#include "WifiCredFuz.cpp" // Wifi and MQTT Credentials
|
||||||
/* with
|
/* with
|
||||||
@ -70,8 +67,8 @@ Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, MQTT_SERVERPORT, MQTT_USERNAME,
|
|||||||
|
|
||||||
/****************************** Feeds ***************************************/
|
/****************************** Feeds ***************************************/
|
||||||
|
|
||||||
// Setup a feed called 'pub_piedthon' for publishing.
|
// Setup a feed called 'pub_photocell' for publishing.
|
||||||
Adafruit_MQTT_Publish pub_piedthon = Adafruit_MQTT_Publish(&mqtt, "piedthon/debug");
|
Adafruit_MQTT_Publish pub_photocell = Adafruit_MQTT_Publish(&mqtt, "piedthon/debug");
|
||||||
|
|
||||||
// Setup a feed called 'sub_piedthon' for subscribing to changes.
|
// Setup a feed called 'sub_piedthon' for subscribing to changes.
|
||||||
Adafruit_MQTT_Subscribe sub_piedthon = Adafruit_MQTT_Subscribe(&mqtt, "piedthon/input");
|
Adafruit_MQTT_Subscribe sub_piedthon = Adafruit_MQTT_Subscribe(&mqtt, "piedthon/input");
|
||||||
@ -117,7 +114,7 @@ void messageToPiedthon(char *msg) {
|
|||||||
digitalWrite(GPIO_ROUGE, LOW);
|
digitalWrite(GPIO_ROUGE, LOW);
|
||||||
digitalWrite(GPIO_VERT, LOW);
|
digitalWrite(GPIO_VERT, LOW);
|
||||||
break;
|
break;
|
||||||
case '1' : // ROUGE
|
case '1' : // ROUGE
|
||||||
digitalWrite(GPIO_VERT, HIGH);
|
digitalWrite(GPIO_VERT, HIGH);
|
||||||
digitalWrite(GPIO_ROUGE, LOW);
|
digitalWrite(GPIO_ROUGE, LOW);
|
||||||
break;
|
break;
|
||||||
@ -125,7 +122,7 @@ void messageToPiedthon(char *msg) {
|
|||||||
digitalWrite(GPIO_VERT, LOW);
|
digitalWrite(GPIO_VERT, LOW);
|
||||||
digitalWrite(GPIO_ROUGE, HIGH);
|
digitalWrite(GPIO_ROUGE, HIGH);
|
||||||
break;
|
break;
|
||||||
case '3' : // Rien
|
case '3' : // Rien
|
||||||
digitalWrite(GPIO_ROUGE, HIGH);
|
digitalWrite(GPIO_ROUGE, HIGH);
|
||||||
digitalWrite(GPIO_VERT, HIGH);
|
digitalWrite(GPIO_VERT, HIGH);
|
||||||
break;
|
break;
|
||||||
@ -138,6 +135,7 @@ void messageToPiedthon(char *msg) {
|
|||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(10);
|
delay(10);
|
||||||
Serial.println(F("Adafruit MQTT PiedThon remix"));
|
Serial.println(F("Adafruit MQTT PiedThon remix"));
|
||||||
@ -145,51 +143,16 @@ void setup() {
|
|||||||
pinMode(GPIO_VERT, OUTPUT);
|
pinMode(GPIO_VERT, OUTPUT);
|
||||||
pinMode(GPIO_ROUGE, OUTPUT);
|
pinMode(GPIO_ROUGE, OUTPUT);
|
||||||
|
|
||||||
randomSeed(analogRead(0));
|
|
||||||
|
|
||||||
setupWifi();
|
setupWifi();
|
||||||
|
|
||||||
// Setup MQTT subscription for onoff feed.
|
// Setup MQTT subscription for onoff feed.
|
||||||
mqtt.subscribe(&sub_piedthon);
|
mqtt.subscribe(&sub_piedthon);
|
||||||
|
|
||||||
|
|
||||||
ArduinoOTA.setHostname(ESP_HOSTNAME);
|
|
||||||
ArduinoOTA.onStart([]() { // switch off all the GPIOs during upgrade
|
|
||||||
digitalWrite(GPIO_ROUGE, HIGH);
|
|
||||||
digitalWrite(GPIO_VERT, HIGH);
|
|
||||||
});
|
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
|
||||||
/*if (progress % (total / 4) == 0) {
|
|
||||||
digitalWrite(GPIO_ROUGE, random(2) ? LOW : HIGH);
|
|
||||||
digitalWrite(GPIO_VERT, random(2) ? LOW : HIGH);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
ArduinoOTA.onEnd([]() { // do a fancy thing with our board led at end
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
int RANDOM_GPIO = GPIO_ROUGE;
|
|
||||||
if (random(2)) { // random(2) returns 0 or 1 randomly
|
|
||||||
RANDOM_GPIO = GPIO_VERT;
|
|
||||||
}
|
|
||||||
digitalWrite(RANDOM_GPIO, !digitalRead(RANDOM_GPIO));
|
|
||||||
delay(400);
|
|
||||||
}
|
|
||||||
digitalWrite(GPIO_ROUGE, LOW);
|
|
||||||
digitalWrite(GPIO_VERT, LOW);
|
|
||||||
});
|
|
||||||
|
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
|
||||||
(void)error;
|
|
||||||
ESP.restart();
|
|
||||||
});
|
|
||||||
ArduinoOTA.begin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
MQTT_connect();
|
MQTT_connect();
|
||||||
ArduinoOTA.handle();
|
|
||||||
|
|
||||||
Adafruit_MQTT_Subscribe *subscription;
|
Adafruit_MQTT_Subscribe *subscription;
|
||||||
while ((subscription = mqtt.readSubscription(5000))) {
|
while ((subscription = mqtt.readSubscription(5000))) {
|
||||||
@ -200,3 +163,4 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user