add GET functionality

pull/151/head
Timm Bogner 1 year ago
parent 47a37f325d
commit 4c411a053e

@ -8,6 +8,8 @@
#include "fdrs_sensor_config.h"
#include <fdrs_node.h>
#define
#define CONTROL_1 101 //Address for controller 1
#define CONTROL_2 102 //Address for controller 2
#define CONTROL_3 103 //Address for controller 3
@ -24,29 +26,71 @@ int status_3 = 0;
int status_4 = 0;
bool newData = false;
bool newStatus = false;
void fdrs_recv_cb(DataReading theData) {
DBG(String(theData.id));
switch (theData.id) {
case CONTROL_1:
status_1 = (int)theData.d;
newData = true;
break;
case CONTROL_2:
status_2 = (int)theData.d;
newData = true;
switch (theData.t) {
case 0: // Incoming command is to SET a value
switch (theData.id) {
case CONTROL_1:
status_1 = (int)theData.d;
newData = true;
break;
case CONTROL_2:
status_2 = (int)theData.d;
newData = true;
break;
case CONTROL_3:
status_3 = (int)theData.d;
newData = true;
break;
case CONTROL_4:
status_4 = (int)theData.d;
newData = true;
break;
}
break;
case CONTROL_3:
status_3 = (int)theData.d;
newData = true;
break;
case CONTROL_4:
status_4 = (int)theData.d;
newData = true;
case 1: // Incoming command is to GET a value
switch (theData.id) {
case CONTROL_1:
if (digitalRead(COIL_1) == HIGH) {
loadFDRS(1, STATUS_T, CONTROL_1);
} else {
loadFDRS(0, STATUS_T, CONTROL_1);
}
break;
case CONTROL_2:
if (digitalRead(COIL_2) == HIGH) {
loadFDRS(1, STATUS_T, CONTROL_2);
} else {
loadFDRS(0, STATUS_T, CONTROL_2);
}
break;
case CONTROL_3:
if (digitalRead(COIL_3) == HIGH) {
loadFDRS(1, STATUS_T, CONTROL_3);
} else {
loadFDRS(0, STATUS_T, CONTROL_3);
}
break;
case CONTROL_4:
if (digitalRead(COIL_4) == HIGH) {
loadFDRS(1, STATUS_T, CONTROL_4);
} else {
loadFDRS(0, STATUS_T, CONTROL_4);
}
break;
}
newStatus = true;
break;
}
}
void checkCoils() { // Sends back a status report for each coil pin.
void checkCoils() { // Sends back a status report for each coil pin.
if (digitalRead(COIL_1) == HIGH) {
loadFDRS(1, STATUS_T, CONTROL_1);
} else {
@ -125,4 +169,12 @@ void loop() {
updateCoils();
checkCoils();
}
if (newStatus) {
newStatus = false;
if (sendFDRS()) {
DBG("Packet received by gateway");
} else {
DBG("Unable to communicate with gateway!");
}
}
}

Loading…
Cancel
Save