Here is my example code. The issue appears to be related to the mesh interrupts, since I wasn’t able to replicate the issue with just local data. This version of the code subscribes to 2 mesh datafeeds
/***************************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME280 Breakout
----> http://www.adafruit.com/products/2650
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface. The device's I2C address is either 0x76 or 0x77.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
See the LICENSE file for details.
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK D4
#define BME_MISO D3
#define BME_MOSI D2
#define BME_CS D5
#define SEALEVELPRESSURE_HPA (1013.25)
//#include <Adafruit_IO_Client.h>
#include "Adafruit_IO_Client.h" // Adafruit IO Librarys
#include "Adafruit_IO_Particle.h"
#define AIO_KEY "AIO_Key_inserted_here" // Adafruit IO AIO Key
TCPClient client; // TCP Client used by Adafruit IO library
// Create the AIO client object
Adafruit_IO_Client AIOClient = Adafruit_IO_Client(client, AIO_KEY);
// Create meshfeed object to get data
Adafruit_IO_Feed tempFeed = AIOClient.getFeed("argon.temp");
Adafruit_IO_Feed tempFeedx = AIOClient.getFeed("xenon.temp");
Adafruit_IO_Feed humidFeed = AIOClient.getFeed("argon.humid");
Adafruit_IO_Feed humidFeedx = AIOClient.getFeed("xenon.humid");
Adafruit_IO_Feed presFeed = AIOClient.getFeed("argon.pres");
Adafruit_IO_Feed presFeedx = AIOClient.getFeed("xenon.pres");
Adafruit_IO_Feed tempFeedx2 = AIOClient.getFeed("xenon2.temp");
Adafruit_IO_Feed humidFeedx2 = AIOClient.getFeed("xenon2.humid");
Adafruit_IO_Feed presFeedx2 = AIOClient.getFeed("xenon2.pres");
const char *FIELD_SEPARATOR = "||";
const char *EVENT_NAME = "tempSensor";
const char *EVENT_NAME2 = "mesh_pub";
const char *EVENT_NAME3 = "temp_pub";
const char *EVENT_NAME4 = "AIO_disconnect";
const char *EVENT_NAME5 = "Argon_hostname";
char buf[256];
bool AIO_OK;
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime, resetTime;
int event1;
void setup()
{
String deviceid = System.deviceID();
Particle.publish(EVENT_NAME5, deviceid , PRIVATE);
// Start the Adafruit IO Client
AIOClient.begin();
// Reset polling timer to use timer instead of delay
event1 = millis();
Serial.begin(9600);
while (!Serial)
; // time to get serial running
Serial.println(F("BME280 test"));
unsigned status;
// default settings
// (you can also pass in a Wire library object like &Wire2)
status = bme.begin();
if (!status)
{
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x");
Serial.println(bme.sensorID(), 16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1)
;
}
Mesh.subscribe("xenon1mesh", meshHandler1);
Mesh.subscribe("xenon2mesh", meshHandler2);
Serial.println("-- Default Test --");
delayTime = 60000;
// SYSTEM_THREAD(ENABLED);
Serial.println();
}
void loop()
{
// if ( (millis() - event1) > delayTime) // delaytime or more have passed
// {
// printValues();
// event1 = millis(); // reset event timer
// }
printValues();
delay(delayTime);
}
void printValues()
{
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
float temp = (bme.readTemperature() * 9.0) / 5.0 + 32.0; // degrees F
float pressure = bme.readPressure() / 100.0; // hPa
float humidity = bme.readHumidity(); // %
float alt = bme.readAltitude(SEALEVELPRESSURE_HPA);
snprintf(buf, sizeof(buf), "%.02f%s%.02f%s%.01f%s%.01f", temp, FIELD_SEPARATOR, pressure, FIELD_SEPARATOR, humidity, FIELD_SEPARATOR, alt);
Particle.publish(EVENT_NAME, buf , PRIVATE);
AIO_OK = tempFeed.send(temp);
if (!AIO_OK) {
Particle.publish(EVENT_NAME4, "AIO_OK is false" , PRIVATE);
}
humidFeed.send(humidity);
presFeed.send(pressure);
}
void meshHandler1(const char *event, const char *data)
{
//Serial.printlnf("event=%s data=%s", event, data ? data : "NULL");
//float xenonhumid2 = atof(data);
//Particle.publish(EVENT_NAME2, data, PRIVATE);
String meshstr = String(data);
//Particle.publish(EVENT_NAME2, data, PRIVATE);
int commaPosition = meshstr.indexOf(",");
if(commaPosition>-1){
String tempstr = meshstr.substring(0,commaPosition); //send first part to line 1 temp
float xenontemp = atof(tempstr);
tempFeedx.send(xenontemp);
int commaPosition2 = meshstr.indexOf(",",commaPosition+1);
String presstr = meshstr.substring(commaPosition+1,commaPosition2); //send first part to line 1 temp
float xenonpres = atof(presstr);
presFeedx.send(xenonpres);
//Particle.publish(EVENT_NAME2, presstr, PRIVATE);
String humidstr = meshstr.substring(commaPosition2+1); //send last part to line 1 humidity
float xenonhumid = atof(humidstr);
humidFeedx.send(xenonhumid);
//Particle.publish(EVENT_NAME3, humidstr, PRIVATE);
}
//humidFeedx2.send(xenonhumid2);
}
void meshHandler2(const char *event, const char *data)
{
//Serial.printlnf("event=%s data=%s", event, data ? data : "NULL");
//float xenonhumid2 = atof(data);
//Particle.publish(EVENT_NAME2, data, PRIVATE);
String meshstr = String(data);
//Particle.publish(EVENT_NAME2, data, PRIVATE);
int commaPosition = meshstr.indexOf(",");
if(commaPosition>-1){
String tempstr = meshstr.substring(0,commaPosition); //send first part to line 1 temp
float xenontemp = atof(tempstr);
tempFeedx2.send(xenontemp);
//delay(1000);
int commaPosition2 = meshstr.indexOf(",",commaPosition+1);
String presstr = meshstr.substring(commaPosition+1,commaPosition2); //send first part to line 1 temp
float xenonpres = atof(presstr);
presFeedx2.send(xenonpres);
//delay(1000);
//Particle.publish(EVENT_NAME2, presstr, PRIVATE);
String humidstr = meshstr.substring(commaPosition2+1); //send last part to line 1 humidity
float xenonhumid = atof(humidstr);
humidFeedx2.send(xenonhumid);
//delay(1000);
//Particle.publish(EVENT_NAME3, humidstr, PRIVATE);
}
//humidFeedx2.send(xenonhumid2);
}