battery level on / off

This commit is contained in:
Verkehrsrot 2019-08-30 18:53:30 +02:00
parent 65045b3cad
commit 679582857a
3 changed files with 41 additions and 6 deletions

View File

@ -169,7 +169,7 @@ Output of sensor and peripheral data is internally switched by a bitmask registe
| 4 | User sensor 1 |
| 5 | User sensor 2 |
| 6 | User sensor 3 |
| 7 | reserved |
| 7 | Batterylevel |
# Time sync
@ -392,17 +392,26 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
0 = BME data off
1 = BME data on, sends BME data on port 7 [default]
0x15 set battery data on/off
0 = battery data off [default]
1 = battery data on, sends voltage on port 8
0x80 get device configuration
Device answers with it's current configuration on Port 3.
0x81 get device status
Device answers with it's current status on Port 2.
Device answers with it's current status on Port 2.
0x83 get battery status
Device answers with battery voltage on Port 8.
0x84 get device GPS status
Device answers with it's current status on Port 4.
Device answers with it's current status on Port 4.
0x85 get BME280 / BME680 sensor data

View File

@ -8,6 +8,10 @@ static const char TAG[] = "flash";
nvs_handle my_handle;
esp_err_t err;
#define PAYLOADMASK \
(GPS_DATA | ALARM_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | \
SENSOR2_DATA | SENSOR3_DATA & ~BATT_DATA)
// populate cfg vars with factory settings
void defaultConfig() {
cfg.lorasf = LORASFDEFAULT; // 7-12, initial lora sf, see pacounter.conf
@ -29,7 +33,7 @@ void defaultConfig() {
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
cfg.monitormode = 0; // 0=disabled, 1=enabled
cfg.runmode = 0; // 0=normal, 1=update
cfg.payloadmask = 0xFF; // all payload switched on
cfg.payloadmask = PAYLOADMASK; // all payload switched on
cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] = {
0}; // init BSEC state for BME680 sensor

View File

@ -140,6 +140,16 @@ void set_bme(uint8_t val[]) {
}
}
void set_batt(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set battery mode to %s",
val[0] ? "on" : "off");
if (val[0]) {
cfg.payloadmask |= (uint8_t)BATT_DATA; // set bit in mask
} else {
cfg.payloadmask &= ~(uint8_t)BATT_DATA; // clear bit in mask
}
}
void set_payloadmask(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: set payload mask to %X", val[0]);
cfg.payloadmask = val[0];
@ -288,6 +298,17 @@ void get_bme(uint8_t val[]) {
#endif
};
void get_batt(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get battery voltage");
#ifdef BAT_MEASURE_ADC
payload.reset();
payload.addVoltage(read_voltage());
SendPayload(BATTPORT, prio_normal);
#else
ESP_LOGW(TAG, "Battery voltage not supported");
#endif
};
void get_time(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get time");
payload.reset();
@ -322,8 +343,9 @@ cmd_t table[] = {
{0x0f, set_wifiant, 1, true}, {0x10, set_rgblum, 1, true},
{0x11, set_monitor, 1, true}, {0x12, set_beacon, 7, false},
{0x13, set_sensor, 2, true}, {0x14, set_payloadmask, 1, true},
{0x15, set_bme, 1, true}, {0x80, get_config, 0, false},
{0x81, get_status, 0, false}, {0x84, get_gps, 0, false},
{0x15, set_bme, 1, true}, {0x16, set_batt, 1, true},
{0x80, get_config, 0, false}, {0x81, get_status, 0, false},
{0x83, get_batt, 0, false}, {0x84, get_gps, 0, false},
{0x85, get_bme, 0, false}, {0x86, get_time, 0, false},
{0x87, set_time, 0, false}, {0x99, set_flush, 0, false}};