add pinout support for remote
This commit is contained in:
50
src/main.cpp
50
src/main.cpp
@@ -3,6 +3,10 @@
|
|||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
#define LED 2
|
#define LED 2
|
||||||
|
#define DOWN D1
|
||||||
|
#define UP D2
|
||||||
|
#define STOP D3
|
||||||
|
|
||||||
|
|
||||||
#ifndef STASSID
|
#ifndef STASSID
|
||||||
#define STASSID "CurrywurstPommesMajo"
|
#define STASSID "CurrywurstPommesMajo"
|
||||||
@@ -12,7 +16,6 @@
|
|||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient client(espClient);
|
PubSubClient client(espClient);
|
||||||
|
|
||||||
int myFunction(int, int);
|
|
||||||
void callback(char* topic, byte* payload, unsigned int length);
|
void callback(char* topic, byte* payload, unsigned int length);
|
||||||
void wifiSetup();
|
void wifiSetup();
|
||||||
void mqttSetup();
|
void mqttSetup();
|
||||||
@@ -60,6 +63,12 @@ void initiateAction(int act) {
|
|||||||
Serial.print("Action ");
|
Serial.print("Action ");
|
||||||
Serial.println(act);
|
Serial.println(act);
|
||||||
|
|
||||||
|
digitalWrite(LED, LOW);
|
||||||
|
digitalWrite(act, HIGH);
|
||||||
|
delay(500);
|
||||||
|
digitalWrite(LED, HIGH);
|
||||||
|
digitalWrite(act, LOW);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void callback(char* topic, byte* message, unsigned int length) {
|
void callback(char* topic, byte* message, unsigned int length) {
|
||||||
@@ -68,23 +77,25 @@ void callback(char* topic, byte* message, unsigned int length) {
|
|||||||
Serial.print(". Message: ");
|
Serial.print(". Message: ");
|
||||||
String messageTemp;
|
String messageTemp;
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
for (unsigned int i = 0; i < length; i++) {
|
||||||
Serial.print((char)message[i]);
|
Serial.print((char)message[i]);
|
||||||
messageTemp += (char)message[i];
|
messageTemp += (char)message[i];
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
// If a message is received on the topic esp32/output, you check if the message is either "on" or "off".
|
|
||||||
// Changes the output state according to the message
|
|
||||||
if (String(topic) == "esp32/output") {
|
if (String(topic) == "esp32/output") {
|
||||||
Serial.print("Changing output to ");
|
Serial.print("Changing output to ");
|
||||||
if(messageTemp == "on"){
|
if(messageTemp == "up"){
|
||||||
Serial.println("on");
|
Serial.println("up");
|
||||||
//digitalWrite(ledPin, HIGH);
|
initiateAction(UP);
|
||||||
}
|
}
|
||||||
else if(messageTemp == "off"){
|
else if(messageTemp == "down"){
|
||||||
Serial.println("off");
|
Serial.println("down");
|
||||||
//digitalWrite(ledPin, LOW);
|
initiateAction(DOWN);
|
||||||
|
}
|
||||||
|
else if (messageTemp == "stop") {
|
||||||
|
Serial.println("stop");
|
||||||
|
initiateAction(STOP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,6 +104,13 @@ void callback(char* topic, byte* message, unsigned int length) {
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
pinMode(LED, OUTPUT);
|
pinMode(LED, OUTPUT);
|
||||||
|
pinMode(DOWN, OUTPUT);
|
||||||
|
pinMode(UP, OUTPUT);
|
||||||
|
pinMode(STOP, OUTPUT);
|
||||||
|
digitalWrite(LED, LOW);
|
||||||
|
digitalWrite(DOWN, LOW);
|
||||||
|
digitalWrite(UP, LOW);
|
||||||
|
digitalWrite(STOP, LOW);
|
||||||
wifiSetup();
|
wifiSetup();
|
||||||
client.setServer("muckibude.fritz.box", 1883);
|
client.setServer("muckibude.fritz.box", 1883);
|
||||||
client.setCallback(callback);
|
client.setCallback(callback);
|
||||||
@@ -104,17 +122,5 @@ void loop() {
|
|||||||
mqttReconnect();
|
mqttReconnect();
|
||||||
}
|
}
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
myFunction(1,2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// put function definitions here:
|
|
||||||
int myFunction(int x, int y) {
|
|
||||||
digitalWrite(LED, HIGH);
|
|
||||||
// Serial.println("LED is on");
|
|
||||||
delay(1000);
|
|
||||||
digitalWrite(LED, LOW);
|
|
||||||
// Serial.println("LED is off");
|
|
||||||
delay(1000);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user