Compare commits

..

No commits in common. "955aa7a8ddc245f9ac35e51c2649999bb57f0af0" and "9f899a480278ffc477081400b16a97da77269336" have entirely different histories.

7 changed files with 31 additions and 188 deletions

2
.gitignore vendored
View File

@ -36,5 +36,3 @@
*.bin
credentials.h
!schematic/KiCad/ATMEGA328PU_lowPower_weather_station/*
src/app/*
!src/app/*.ino

View File

@ -1,117 +0,0 @@
#include "definition.h"
#include "BoardConfig.h"
#include "WSPeripherals.h"
#include <LowPower.h>
BoardConfig defaultBC;
WSPeripherals WSP(defaultBC);
uint8_t sleepSlots(0), rCode(0);
DataPacket payload;
void setup()
{
#if SERIAL_DEBUG_ENABLED == 1
Serial.begin(SERIAL_BAUD_RATE);
Serial.println("Setup begin");
#endif
rCode = WSP.init();
memset(&payload, 0, sizeof(payload));
#if SERIAL_DEBUG_ENABLED == 1
Serial.print("Payload size : ");Serial.println(sizeof payload);
debugStruct(&payload);
#endif
payload.header = WEATHER_STATION;
#if SERIAL_DEBUG_ENABLED == 1
Serial.print("WSP init returned : ");Serial.println(rCode);
Serial.println("Setup end");
#endif
}
void loop()
{
if(sleepSlots == SLEEP_4_SEC_INTERVAL || !sleepSlots)
{
//We get all the measurements.
WSP.externalPeripherals(WSPeripherals::ON);
rCode = WSP.initExternalPeripherals();
#if SERIAL_DEBUG_ENABLED == 1
Serial.print("WSP peripheral init returned : ");Serial.println(rCode);
#endif
payload.battery = WSP.batteryVoltage();
payload.ldr = WSP.sunlightMeasurement();
WSP.temperatureAndATMPressureFromBMP280(&payload.bmpTemp, &payload.bmpPress);
payload.humidity = WSP.humidity();
payload.compensatedHumidity = WSP.compensatedHumidity();
payload.htuTemp = WSP.temperatureFromHTU21();
#if SERIAL_DEBUG_ENABLED == 1
debugStruct(&payload);
#endif
//We send it over the air.
if(WSP.getRadio().isChipConnected())
{
WSP.applyRadioConfig();
WSP.getRadio().setRetries(10,20);
WSP.getRadio().openWritingPipe((const uint8_t *)RADIO_NODE_ADDRESS);
//WSP.getRadio().setPayloadSize(sizeof payload);
bool result = WSP.getRadio().write(&payload, sizeof(payload));
#if SERIAL_DEBUG_ENABLED == 1
if(result)
Serial.println("Payload sent !");
else
Serial.println("Failed to send payload !");
delay(100);
#endif
}
#if SERIAL_DEBUG_ENABLED == 1
else
{
Serial.println("NRF missing !");
delay(100);
}
#endif
WSP.externalPeripherals(WSPeripherals::OFF);
payload.id++;
sleepSlots = 0;
}
//Lets sleep for 4 secondes
LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
sleepSlots++;
}
void debugStruct(DataPacket *p)
{
Serial.println("##############DATA##############");
Serial.print("ID : ");
Serial.println(p->id);
Serial.print("HEADER : ");
Serial.println(p->header);
Serial.print("BATT : ");
Serial.print(p->battery);
Serial.println(" V");
Serial.print("LDR : ");
Serial.println(p->ldr);
Serial.print("BMP TEMP : ");
Serial.print(p->bmpTemp);
Serial.println(" *C");
Serial.print("BMP PRESS : ");
Serial.print(p->bmpPress);
Serial.println(" Pa");
Serial.print("HUM : ");Serial.println(p->humidity);
Serial.print("COM HUM : ");Serial.println(p->compensatedHumidity);
Serial.print("HTU TEMP : ");Serial.println(p->htuTemp);
}

View File

@ -10,7 +10,7 @@ uint8_t WSPeripherals::init()
pinMode(_boardConfig.LDOEnable, OUTPUT);
_3V3PowerRail(OFF);
pinMode(_boardConfig.LDRVSensEnable, OUTPUT);
digitalWrite(_boardConfig.LDRVSensEnable, HIGH); //High means that it is disabled and low is active /!\/
digitalWrite(_boardConfig.LDRVSensEnable, HIGH); //High means that it is disabled and low is active /!\
pinMode(_boardConfig.BATVSensEnable, OUTPUT);
digitalWrite(_boardConfig.BATVSensEnable, LOW);
@ -41,15 +41,15 @@ uint8_t WSPeripherals::init()
uint8_t WSPeripherals::initExternalPeripherals()
{
uint8_t toReturn(0);
_BMP280.setSampling( Adafruit_BMP280::MODE_FORCED,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_4000);
toReturn |= _BMP280.begin(0x76);
toReturn |= _HTU21.begin() << 1;
toReturn |= _NRF.begin() << 2;
//We disable the I2C internal pullups :
digitalWrite(SDA, LOW);
digitalWrite(SCL, LOW);
return toReturn;
}
@ -73,20 +73,14 @@ int WSPeripherals::sunlightMeasurement()
return rawSunlightMeasurement;
}
void WSPeripherals::temperatureAndATMPressureFromBMP280(float *temperature, float *ATMPressure)
float WSPeripherals::temperatureFromBMP280()
{
if(!temperature && !ATMPressure)return;
_BMP280.setSampling( Adafruit_BMP280::MODE_FORCED,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_4000);
if(temperature)
*temperature = _BMP280.readTemperature();
if(ATMPressure)
*ATMPressure = _BMP280.readPressure();
return _BMP280.readTemperature();
}
float WSPeripherals::ATMPressure()
{
return _BMP280.readPressure();
}
float WSPeripherals::temperatureFromHTU21()
@ -107,15 +101,7 @@ float WSPeripherals::compensatedHumidity()
void WSPeripherals::_3V3PowerRail(State state)
{
digitalWrite(_boardConfig.LDOEnable, state);
if(state) //We let some time for the voltage to stabilize on the rail.
delay(2);
}
const RF24 &WSPeripherals::getRadio(){return _NRF;}
void WSPeripherals::applyRadioConfig(uint8_t channel, uint8_t paLevel, rf24_datarate_e datarate)
{
_NRF.setChannel(channel);
_NRF.setPALevel(paLevel);
_NRF.setDataRate(datarate);
}
void WSPeripherals::applyRadioConfig(uint8_t channel = RADIO_CHANNEL, uint8_t paLevel = RADIO_PA_LEVEL, rf24_datarate_e datarate = RADIO_DATARATE);

View File

@ -36,7 +36,8 @@ class WSPeripherals
float batteryVoltage();
int sunlightMeasurement();
void temperatureAndATMPressureFromBMP280(float *temperature = NULL, float *ATMPressure = NULL);
float temperatureFromBMP280();
float ATMPressure();
float temperatureFromHTU21();
float humidity();
float compensatedHumidity();
@ -44,7 +45,12 @@ class WSPeripherals
/*
* Before calling this method, externalPeripherals(ON) and initExternalPeripherals() must be called respectively
*/
void applyRadioConfig(uint8_t channel = RADIO_CHANNEL, uint8_t paLevel = RADIO_PA_LEVEL, rf24_datarate_e datarate = RADIO_DATARATE);
void applyRadioConfig(uint8_t channel, uint8_t paLevel, rf24_datarate_e datarate)
{
_NRF.setChannel(channel);
_NRF.setPALevel(paLevel);
_NRF.setDataRate(rf24_datarate_e);
}
const RF24 &getRadio();
protected:

View File

@ -8,10 +8,9 @@
#include <Arduino.h>
#include <RF24.h>
#include "packet_format.h"
//Serial debug config part
#define SERIAL_DEBUG_ENABLED 1
#define SERIAL_DEBUG_ENABLED 0
#define SERIAL_BAUD_RATE 115200
//Battery config part
@ -24,9 +23,6 @@
#define RADIO_PA_LEVEL RF24_PA_MAX
#define RADIO_DATARATE RF24_250KBPS
//Seep config part
#define SLEEP_4_SEC_INTERVAL 1//15
//Pin config part
typedef enum
{
@ -44,18 +40,4 @@ typedef enum
A1_LDR_V_SENS = A1,
} Pin;
//Payload structure
typedef struct
{
uint16_t id;
HEADER_e header : 6;
unsigned int ldr : 10;
float battery;
float bmpTemp;
float bmpPress;
float humidity;
float compensatedHumidity;
float htuTemp;
} DataPacket __attribute__((__packed__));
#endif //DEFINITION_H

View File

@ -1,6 +0,0 @@
#ifndef PACKET_FORMAT_H
#define PACKET_FORMAT_H
enum HEADER_e {WEATHER_STATION = 0};
#endif //PACKET_FORMAT_H

View File

@ -14,17 +14,16 @@
BoardConfig defaultBC; //Default config is applied
WSPeripherals WSP(defaultBC);
float BMPTemperature(0), ATMPressure(0);
void setup()
{
Serial.begin(SERIAL_BAUD_RATE);
Serial.println("Setup begin");
uint8_t code = WSP.init();
Serial.print("WSP init returned : ");Serial.println(code);
Serial.print("WSP init returned : ");Serial.print(code);
WSP.externalPeripherals(WSPeripherals::ON);
code = WSP.initExternalPeripherals();
Serial.print("WSP init external peripheral returned : ");Serial.println(code);
Serial.print("WSP init external peripheral returned : ");Serial.print(code);
Serial.println("Setup end");
}
@ -38,30 +37,25 @@ void loop()
Serial.print("LDR : ");
Serial.println(WSP.sunlightMeasurement());
WSP.temperatureAndATMPressureFromBMP280(&BMPTemperature, &ATMPressure);
Serial.print("BMP TEMP : ");
Serial.print(BMPTemperature);
Serial.println(" *C");
Serial.print("HTU TEMP : ");
Serial.print(WSP.temperatureFromHTU21());
Serial.print(WSP.temperatureFromBMP280());
Serial.println(" *C");
Serial.print("BMP PRESS : ");
Serial.print(ATMPressure);
Serial.print(WSP.ATMPressure());
Serial.println(" Pa");
Serial.print("HUM : ");Serial.println(WSP.humidity());
Serial.print("COM HUM : ");Serial.println(WSP.compensatedHumidity());
Serial.print("HTU TEMP : ");Serial.println(WSP.temperatureFromHTU21());
if(!WSP.getRadio().isChipConnected())
{
Serial.println("Radio is missing");
Serial.println("Chip is missing");
}
else
{
Serial.println("Radio is present");
Serial.println("Chip is present");
}
delay(1000);