Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.