Created
August 18, 2019 14:59
-
-
Save justind000/7d34f3257aa960e62748ec870e4ce33d to your computer and use it in GitHub Desktop.
NoCAN
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
#include <nocan.h> | |
#include <ArduinoJson.h> | |
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10610 | |
#include <uFire_EC_JSON.h> | |
#include <uFire_pH_JSON.h> | |
#include <uFire_ORP_JSON.h> | |
NocanChannelId tid; | |
uFire_EC_JSON ec; | |
uFire_pH_JSON ph; | |
uFire_ORP_JSON orp; | |
void setup() { | |
Serial1.begin(9600); | |
Nocan.open(); | |
Nocan.registerChannel("ufire", &tid); | |
Nocan.subscribeChannel(tid); | |
ec.begin(new uFire_EC); | |
ph.begin(new ISE_pH); | |
orp.begin(new ISE_ORP(0x3e)); | |
Wire.begin(); | |
} | |
void loop() { | |
NocanMessage msg; | |
int8_t status = Nocan.receiveMessage(&msg); | |
if (status == 0) | |
{ | |
String rx_command = (char*)msg.data; | |
rx_command = rx_command.substring(0, msg.data_len); | |
Nocan.publishMessage(tid, rx_command.c_str()); | |
Serial1.println(rx_command); | |
String json_out = ec.processJSON(rx_command); | |
if (json_out != "") | |
{ | |
Nocan.publishMessage(tid, json_out.c_str()); | |
return; | |
} | |
// try pH | |
json_out = ph.processJSON(rx_command); | |
if (json_out != "") | |
{ | |
Nocan.publishMessage(tid, json_out.c_str()); | |
return; | |
} | |
// try ORP | |
json_out = orp.processJSON(rx_command); | |
if (json_out != "") | |
{ | |
Nocan.publishMessage(tid, json_out.c_str()); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment