Hi!
Running a photon with a couple of dht22 connected to it and would like to send the data to my Home Assistant running on a raspberry. On the raspberry I run influxdb and grafana to save the data and visualize. Anyway, when testing the embedded mqtt with mqttfx I can post values but I can’t figure out the config for particle to send it to the local ip. Now I might have messed up most of my configuration trying out a lot of different things from this and other forums but I attached it below.
// This #include statement was automatically added by the Particle IDE.
#include <SparkFunRHT03.h>
// This #include statement was automatically added by the Particle IDE.
#include <MQTT.h>
void callback(char* topic, byte* payload, unsigned int length);
byte server[] = { 192,168,8,109 };
MQTT client(server, 1883, callback);
/////////////////////
// Pin Definitions //
/////////////////////
const int RHT03_DATA_PIN_1 = D1; // RHT03 data pin
const int RHT03_DATA_PIN_2 = D3; // RHT03 data pin
double latestHumidity_1;
double latestHumidity_2;
String temp1;
//STARTUP(WiFi.selectAntenna(ANT_INTERNAL)); // selects the CHIP antenna
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL)); // selects the u.FL antenna
///////////////////////////
// RHT03 Object Creation //
///////////////////////////
RHT03 rht1; // This creates a RHT03 object, which we'll use to interact with the sensor
RHT03 rht2; // This creates a RHT03 object, which we'll use to interact with the sensor
// recieve message
void callback(char* topic, byte* payload, unsigned int length) {
char p[length + 1];
memcpy(p, payload, length);
p[length] = NULL;
if (!strcmp(p, "RED"))
RGB.color(255, 0, 0);
else if (!strcmp(p, "GREEN"))
RGB.color(0, 255, 0);
else if (!strcmp(p, "BLUE"))
RGB.color(0, 0, 255);
else
RGB.color(255, 255, 255);
delay(1000);
}
void setup() {
// Call rht.begin() to initialize the sensor and our data pin
rht1.begin(RHT03_DATA_PIN_1);
rht2.begin(RHT03_DATA_PIN_2);
Particle.variable("humidity_1", latestHumidity_1);
Particle.variable("humidity_2", latestHumidity_2);
RGB.control(true);
}
void loop() {
if (client.isConnected())
client.loop();
client.connect("sparkclient");
// Call rht.update() to get new humidity and temperature values from the sensor.
int updateRet_1 = rht1.update();
int updateRet_2 = rht2.update();
// If successful, the update() function will return 1.
// If update fails, it will return a value <0
if (updateRet_1 == 1)
{
// The humidity(), tempC(), and tempF() functions can be called -- after
// a successful update() -- to get the last humidity and temperature
// value
latestHumidity_1 = rht1.humidity();
float latestTempC_1 = rht1.tempC();
latestHumidity_2 = rht2.humidity();
float latestTempC_2 = rht2.tempC();
temp1 = String(latestTempC_1);
if (client.isConnected()) {
client.publish("home-assistant/badrum/temperatur",temp1);
}
}
}