Skip to content

Instantly share code, notes, and snippets.

@justind000
Last active November 13, 2019 17:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save justind000/f2d26807d7f67657642ad2f08286255d to your computer and use it in GitHub Desktop.
Save justind000/f2d26807d7f67657642ad2f08286255d to your computer and use it in GitHub Desktop.
IoT Pool Monitor
#include "ThingsBoard.h"
#include "ISE_pH.h"
#include "ISE_ORP.h"
ISE_pH pH(19, 23);
ISE_ORP ORP(19, 23, 0x3E);
void setup()
{
thingsboard_Init();
}
void loop()
{
String data;
const size_t bufferSize = JSON_OBJECT_SIZE(3);
DynamicJsonBuffer jsonBuffer(bufferSize);
JsonObject& root = jsonBuffer.createObject();
root["pH "] = String(pH.measurepH());
root["mV "] = String(ORP.measureORP());
root["C "] = String(pH.measureTemp());
root.printTo(data);
thingsboard_Publish(data);
client.loop();
}
#include <WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
WiFiClient wifiClient;
PubSubClient client(wifiClient);
// your network information
const char *ssid = "";
const char *password = "";
// get this information from the website
char device[] = "";
char token[] = "";
char server[] = "";
bool thingsboard_Publish(String data) {
if (!client.connected())
{
while (!client.connect(device, token, NULL))
{
delay(100);
}
}
String payload = data;
char attributes[100];
payload.toCharArray(attributes, 100);
client.publish("v1/devices/me/telemetry", attributes);
}
void thingsboard_Init() {
if (strcmp(WiFi.SSID().c_str(), ssid) != 0)
{
WiFi.begin(ssid, password);
}
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
client.setServer(server, 1883);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment