Float values sent in binary format over the air
Move base radio id to MyConfig.h
This commit is contained in:
@@ -8,6 +8,8 @@
|
|||||||
#define RF24_DATARATE RF24_250KBPS //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
|
#define RF24_DATARATE RF24_250KBPS //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
|
||||||
#define RF24_PA_LEVEL RF24_PA_MAX //Sensor PA Level == RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBM, and RF24_PA_MAX=0dBm
|
#define RF24_PA_LEVEL RF24_PA_MAX //Sensor PA Level == RF24_PA_MIN=-18dBm, RF24_PA_LOW=-12dBm, RF24_PA_HIGH=-6dBM, and RF24_PA_MAX=0dBm
|
||||||
#define RF24_PA_LEVEL_GW RF24_PA_LEVEL //Gateway PA Level, defaults to Sensor net PA Level. Tune here if using an amplified nRF2401+ in your gateway.
|
#define RF24_PA_LEVEL_GW RF24_PA_LEVEL //Gateway PA Level, defaults to Sensor net PA Level. Tune here if using an amplified nRF2401+ in your gateway.
|
||||||
|
#define BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL) // This is also act as base value for sensor nodeId addresses. Change this (or channel) if you have more than one sensor network.
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Enable/Disable debug logging
|
* Enable/Disable debug logging
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ char* MyMessage::getString(char *buffer) const {
|
|||||||
case P_ULONG32:
|
case P_ULONG32:
|
||||||
ultoa(ulValue, buffer, 10);
|
ultoa(ulValue, buffer, 10);
|
||||||
break;
|
break;
|
||||||
|
case P_FLOAT32:
|
||||||
|
dtostrf(fValue,2,fPrecision,buffer);
|
||||||
|
break;
|
||||||
case P_CUSTOM:
|
case P_CUSTOM:
|
||||||
return getStream(buffer);
|
return getStream(buffer);
|
||||||
break;
|
break;
|
||||||
@@ -105,8 +108,15 @@ bool MyMessage::getBool() const {
|
|||||||
return getInt();
|
return getInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
double MyMessage::getDouble() const {
|
float MyMessage::getFloat() const {
|
||||||
return strtod(data, NULL);
|
switch(miGetPayloadType()) {
|
||||||
|
case P_FLOAT32:
|
||||||
|
return fValue;
|
||||||
|
case P_STRING:
|
||||||
|
return atof(data);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long MyMessage::getLong() const {
|
long MyMessage::getLong() const {
|
||||||
@@ -195,10 +205,11 @@ MyMessage& MyMessage::set(uint8_t value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MyMessage& MyMessage::set(double value, uint8_t decimals) {
|
MyMessage& MyMessage::set(float value, uint8_t decimals) {
|
||||||
dtostrf(value,2,decimals,data);
|
miSetLength(5); // 32 bit float + persi
|
||||||
miSetLength(strlen(data));
|
miSetPayloadType(P_FLOAT32);
|
||||||
miSetPayloadType(P_STRING);
|
fValue=value;
|
||||||
|
fPrecision = decimals;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ typedef enum {
|
|||||||
} stream;
|
} stream;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM
|
P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM, P_FLOAT32
|
||||||
} payload;
|
} payload;
|
||||||
|
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ public:
|
|||||||
void* getCustom() const;
|
void* getCustom() const;
|
||||||
uint8_t getByte() const;
|
uint8_t getByte() const;
|
||||||
bool getBool() const;
|
bool getBool() const;
|
||||||
double getDouble() const;
|
float getFloat() const;
|
||||||
long getLong() const;
|
long getLong() const;
|
||||||
unsigned long getULong() const;
|
unsigned long getULong() const;
|
||||||
int getInt() const;
|
int getInt() const;
|
||||||
@@ -157,7 +157,7 @@ public:
|
|||||||
MyMessage& set(void* payload, uint8_t length);
|
MyMessage& set(void* payload, uint8_t length);
|
||||||
MyMessage& set(const char* value);
|
MyMessage& set(const char* value);
|
||||||
MyMessage& set(uint8_t value);
|
MyMessage& set(uint8_t value);
|
||||||
MyMessage& set(double value, uint8_t decimals);
|
MyMessage& set(float value, uint8_t decimals);
|
||||||
MyMessage& set(unsigned long value);
|
MyMessage& set(unsigned long value);
|
||||||
MyMessage& set(long value);
|
MyMessage& set(long value);
|
||||||
MyMessage& set(unsigned int value);
|
MyMessage& set(unsigned int value);
|
||||||
@@ -192,6 +192,10 @@ struct
|
|||||||
long lValue;
|
long lValue;
|
||||||
unsigned int uiValue;
|
unsigned int uiValue;
|
||||||
int iValue;
|
int iValue;
|
||||||
|
struct {
|
||||||
|
float fValue;
|
||||||
|
uint8_t fPrecision; // Number of decimals when serializing
|
||||||
|
};
|
||||||
char data[MAX_PAYLOAD + 1];
|
char data[MAX_PAYLOAD + 1];
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -57,8 +57,6 @@
|
|||||||
#define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_FIRMWARE_CRC_ADDRESS+2) // First free address for sketch static configuration
|
#define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_FIRMWARE_CRC_ADDRESS+2) // First free address for sketch static configuration
|
||||||
|
|
||||||
// This is the nodeId for sensor net gateway receiver sketch (where all sensors should send their data).
|
// This is the nodeId for sensor net gateway receiver sketch (where all sensors should send their data).
|
||||||
// This is also act as base value for sensor nodeId
|
|
||||||
#define BASE_RADIO_ID ((uint64_t)0xA8A8E1FC00LL)
|
|
||||||
#define GATEWAY_ADDRESS ((uint8_t)0)
|
#define GATEWAY_ADDRESS ((uint8_t)0)
|
||||||
#define BROADCAST_ADDRESS ((uint8_t)0xFF)
|
#define BROADCAST_ADDRESS ((uint8_t)0xFF)
|
||||||
#define TO_ADDR(x) (BASE_RADIO_ID + x)
|
#define TO_ADDR(x) (BASE_RADIO_ID + x)
|
||||||
|
|||||||
Reference in New Issue
Block a user