so i'm trying to use a BME280 with a EPS8266 wifi board. i can get the mqtt stuff working as the guild says. but it makes for alot more "stuff" in my node red interface (which is trivial). i have a raspberry pi 2 running "Magic Mirror, Node Red, and MQTT" that setup sends a single burst of data over my network for the broker to decide what to do with.
i know alot of useless info. can i take these 3 bunches of code below and send it all as one burst instead of 3?
that is where i'm at a loss, and could use some direction.
void loop() {
unsigned long currentMillis = millis();
// Every X number of seconds (interval = 10 seconds)
// it publishes a new MQTT message
if (currentMillis - previousMillis >= interval) {
// Save the last time a new reading was published
previousMillis = currentMillis;
// New BME280 sensor readings
temp = bme.readTemperature();
//temp = 1.8*bme.readTemperature() + 32;
hum = bme.readHumidity();
pres = bme.readPressure()/100.0F;
// Publish an MQTT message on topic esp/bme280/temperature
uint16_t packetIdPub1 = mqttClient.publish(MQTT_PUB_TEMP, 1, true, String(temp).c_str()); Serial.printf("Publishing on topic %s at QoS 1, packetId: %i ", MQTT_PUB_TEMP, packetIdPub1);
Serial.printf("Message: %.2f \n", temp);
// Publish an MQTT message on topic esp/bme280/humidity
uint16_t packetIdPub2 = mqttClient.publish(MQTT_PUB_HUM, 1, true, String(hum).c_str()); Serial.printf("Publishing on topic %s at QoS 1, packetId: %i ", MQTT_PUB_HUM, packetIdPub2);
Serial.printf("Message: %.2f \n", hum);
// Publish an MQTT message on topic esp/bme280/pressure
uint16_t packetIdPub3 = mqttClient.publish(MQTT_PUB_PRES, 1, true, String(pres).c_str()); Serial.printf("Publishing on topic %s at QoS 1, packetId: %i ", MQTT_PUB_PRES, packetIdPub3);
Serial.printf("Message: %.3f \n", pres);
that is what i get from my raspberry pi running node red. it's a json object, but influxbd should take the data sent and catagorize it in it's database from each input i select in node red
%.2f /n means means "print the specified number to 2 decimal places, followed by /n" whereas %.2f \n means "print the specified number to 2 decimal places, followed by a new line"
blargins this is what i tryed and it's only publising the tempature. i tryed modifying the publish line to add more and the program wouldn't compile. i'm still not seeing anything past the tempature.
You need to put all the text and any formatting characters in one pair of quotes and follow that with a list of the matching variables to be printed, like this
Serial.printf("Publishing on topic %s at QoS 1, packetId: %i ", MQTT_BME280, packetIdPub1);
i get it, it's a learning tool. i'm trying to learn and modify the scrip for my needs. but i'm an idiot and as much as i read these things i don't understand what im missing to get a output string of the 3 items from the bme280. i'm out putting this all to a influxdb database for graphana to display nice and pretty.
how do i serial print the output of temp, humi and press in a single string with the titles temp, humi, and pre like i did above so influxdb can use it?
i wish i could pi zeros all over the place like i was. my problem would be a non isssue, but over the last 2 years testing in my house, the raspberry pi's are not as roubost as the esp8266 on repetly sending out a string of data.