Both times where I make the above call - I receive the compilation error. This used to compile a month ago - not sure if something changed in the Particle world or if I accidentally made a change and can’t find it now…
I’ve had trouble with the latest firmware versions trying to get complex functions to build thier own forward declarations. So, you may want to add a function prototype at the beginning of the .ino file.
Example:
/***************************************************************************
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.
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
This file was modified by Markus Haack (https://github.com/mhaack)
in order to work with Particle Photon & Core.
***************************************************************************/
#include "Adafruit_Sensor.h"
#include "Adafruit_BME280.h"
#include "Particle.h"
#define BME_SCK D4
#define BME_MISO D3
#define BME_MOSI D2
#define BME_CS D5
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
struct Conditions{
double Temperature;
double RelativeHumidity;
double Pressure;
double Altitude;
};
char conditionsJSON[128] = "unavailable";
void getInstrumentData(Conditions* cond);
void updateConditionsJSON(Conditions* cond);
void setup()
{
Serial.begin(9600);
Particle.variable("conditions", conditionsJSON);
Serial.println(F("BME280 test"));
if (!bme.begin())
{
while (1)
{
Particle.process();
Serial.println("Could not find a valid BME280 sensor, check wiring!");
delay(1000);
}
}
}
void loop()
{
static uint32_t lastSerialUpdateMillis = 0;
if(millis() - lastSerialUpdateMillis > 15 * 1000)
{
Conditions conditions;
getInstrumentData(&conditions);
updateConditionsJSON(&conditions);
serialPrintData();
lastSerialUpdateMillis = millis();
}
}
void getInstrumentData(Conditions* cond)
{
cond->RelativeHumidity = bme.readHumidity();
cond->Temperature = bme.readTemperature() * 9.0F / 5.0F + 32.0F;
cond->Pressure = bme.readPressure() / 100.0F;
cond->Altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
}
void updateConditionsJSON(Conditions* cond)
{
snprintf(conditionsJSON, sizeof(conditionsJSON), "{\"temperature\":%f,\"humidity\":%f,\"pressure\":%f,\"altitude\":%f}", cond->Temperature, cond->RelativeHumidity, cond->Pressure, cond->Altitude);
}
void serialPrintData(void)
{
Serial.println(conditionsJSON);
}
@BulldogLowell, it’s important to note that instead of passing around structs, you pass around pointers to structs. To me, this is the most important take-away here
Hi Peekay123 - hmmm, this might be the bigger deal - this is one of the the problems with being a Java program that later in life starts developing in C.
So in the bigger picture, I have a rolling history of these structs - amazingly enough I sample at 50hz and save the data for 10 seconds. It’s somewhat resource hungry but seems to work great.
My approach is to create a new struct each time I sample my accelerometer and then push that struct onto my array of historical data (500 element array)…
If I was to use a pointer instead - would my array just be an array of pointers to the structs that are defined and populated inside my function that gets the sensor readings (struct SensorReadings getSensorReadings())?