Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send data or alerts to Telegram Messenger chat #442

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion multigeiger/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ static const char *status_chars[STATUS_MAX] = {
".t3T?", // ST_TTN_OFF, ST_TTN_IDLE, ST_TTN_ERROR, ST_TTN_SENDING, ST_TTN_INIT
// group BlueTooth
".B4b?", // ST_BLE_OFF, ST_BLE_CONNECTED, ST_BLE_ERROR, ST_BLE_CONNECTABLE, ST_BLE_INIT
// group Telegram
".g5G?", // ST_TELEGRAM_OFF, ST_TELEGRAM_IDLE, ST_TELEGRAM_ERROR, ST_TELEGRAM_SENDING, ST_TELEGRAM_INIT
// group other
".", // ST_NODISPLAY
".", // ST_NODISPLAY
".H7", // ST_NODISPLAY, ST_HV_OK, ST_HV_ERROR
};

Expand Down
7 changes: 6 additions & 1 deletion multigeiger/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ void display_statusline(String txt);
#define ST_BLE_CONNECTABLE 3
#define ST_BLE_INIT 4

// status index 5 is still free
#define STATUS_TELEGRAM 5
#define ST_TELEGRAM_OFF 0
#define ST_TELEGRAM_IDLE 1
#define ST_TELEGRAM_ERROR 2
#define ST_TELEGRAM_SENDING 3
#define ST_TELEGRAM_INIT 4

// status index 6 is still free

Expand Down
35 changes: 23 additions & 12 deletions multigeiger/multigeiger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

// DIP switches
static Switches switches;

float accumulated_Count_Rate = 0.0, accumulated_Dose_Rate = 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit dirty considering i just got rid of most of the global variables mess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. But it would be equally bad style to redo the whole dose calculation with local storage of the previous state from "publish" again in "transmit". I think it might be time to merge all the activities with dose & count stuff in a single function...? Maybe we should indeed meet e.g. at ShackSpace and refactor first on the whiteboard and then directly in code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s. #444


void setup() {
bool isLoraBoard = init_hwtest();
Expand Down Expand Up @@ -107,14 +107,13 @@ int update_ble_status(void) { // currently no error detection
}

void publish(unsigned long current_ms, unsigned long current_counts, unsigned long gm_count_timestamp, unsigned long current_hv_pulses,
float temperature, float humidity, float pressure) {
bool have_thp, float temperature, float humidity, float pressure, int wifi_status) {
static unsigned long last_timestamp = millis();
static unsigned long last_counts = 0;
static unsigned long last_hv_pulses = 0;
static unsigned long last_count_timestamp = 0;
static unsigned int accumulated_GMC_counts = 0;
static unsigned long accumulated_time = 0;
static float accumulated_Count_Rate = 0.0, accumulated_Dose_Rate = 0.0;

if (((current_counts - last_counts) >= MINCOUNTS) || ((current_ms - last_timestamp) >= DISPLAYREFRESH)) {
if ((gm_count_timestamp == 0) && (last_count_timestamp == 0)) {
Expand Down Expand Up @@ -149,13 +148,21 @@ void publish(unsigned long current_ms, unsigned long current_counts, unsigned lo
(showDisplay && switches.display_on));

// Sound local alarm?
if (soundLocalAlarm && GMC_factor_uSvph > 0) {
if (accumulated_Dose_Rate > localAlarmThreshold) {
log(WARNING, "Local alarm: Accumulated dose of %.3f µSv/h above threshold at %.3f µSv/h", accumulated_Dose_Rate, localAlarmThreshold);
alarm();
} else if (Dose_Rate > (accumulated_Dose_Rate * localAlarmFactor)) {
log(WARNING, "Local alarm: Current dose of %.3f > %d x accumulated dose of %.3f µSv/h", Dose_Rate, localAlarmFactor, accumulated_Dose_Rate);
alarm();
if ((soundLocalAlarm || sendLocalAlarmToMessenger) && GMC_factor_uSvph > 0) {
if ((accumulated_Dose_Rate > localAlarmThreshold) || (Dose_Rate > (accumulated_Dose_Rate * localAlarmFactor))) {
if (accumulated_Dose_Rate > localAlarmThreshold) {
log(WARNING, "Local alarm: Accumulated dose of %.3f µSv/h above threshold at %.3f µSv/h", accumulated_Dose_Rate, localAlarmThreshold);
} else {
log(WARNING, "Local alarm: Current dose of %.3f > %d x accumulated dose of %.3f µSv/h", Dose_Rate, localAlarmFactor, accumulated_Dose_Rate);
}
if (soundLocalAlarm) {
alarm();
}
if (sendLocalAlarmToMessenger) {
transmit_userinfo(tubes[TUBE_TYPE].type, tubes[TUBE_TYPE].nbr, tubes[TUBE_TYPE].cps_to_uSvph,
(unsigned int)(Count_Rate * 60), (unsigned int)(accumulated_Count_Rate * 60), accumulated_Dose_Rate,
have_thp, temperature, humidity, pressure, wifi_status, true);
}
}
}

Expand Down Expand Up @@ -236,8 +243,12 @@ void transmit(unsigned long current_ms, unsigned long current_counts, unsigned l

log(DEBUG, "Measured GM: cpm= %d HV=%d", current_cpm, hv_pulses);

transmit_data(tubes[TUBE_TYPE].type, tubes[TUBE_TYPE].nbr, dt, hv_pulses, counts, current_cpm,
transmit_data(tubes[TUBE_TYPE].type, tubes[TUBE_TYPE].nbr,
dt, hv_pulses, counts, current_cpm,
Comment on lines -239 to +247
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this beyond some line length limit or why did you reformat this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe wordwrap from my editor? will check

have_thp, temperature, humidity, pressure, wifi_status);
transmit_userinfo(tubes[TUBE_TYPE].type, tubes[TUBE_TYPE].nbr, tubes[TUBE_TYPE].cps_to_uSvph,
current_cpm, accumulated_Count_Rate, accumulated_Dose_Rate,
have_thp, temperature, humidity, pressure, wifi_status, false);
}
}

Expand Down Expand Up @@ -283,7 +294,7 @@ void loop() {
// do any other periodic updates for uplinks
poll_transmission();

publish(current_ms, gm_counts, gm_count_timestamp, hv_pulses, temperature, humidity, pressure);
publish(current_ms, gm_counts, gm_count_timestamp, hv_pulses, have_thp, temperature, humidity, pressure, wifi_status);

if (Serial_Print_Mode == Serial_One_Minute_Log)
one_minute_log(current_ms, gm_counts);
Expand Down
79 changes: 74 additions & 5 deletions multigeiger/transmission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Arduino.h>
#include <WiFiClientSecure.h>
#include <HTTPClient.h>
#include <UniversalTelegramBot.h>

#include "log.h"
#include "display.h"
Expand Down Expand Up @@ -41,7 +42,8 @@ typedef struct https_client {
HTTPClient *hc;
} HttpsClient;

static HttpsClient c_madavi, c_sensorc, c_customsrv;
static HttpsClient c_madavi, c_sensorc, c_customsrv, c_telegram;
UniversalTelegramBot *telegram_bot;

void setup_transmission(const char *version, char *ssid, bool loraHardware) {
chipID = String(ssid);
Expand Down Expand Up @@ -69,9 +71,22 @@ void setup_transmission(const char *version, char *ssid, bool loraHardware) {
c_customsrv.wc->setCACert(ca_certs);
c_customsrv.hc = new HTTPClient;

if ((strlen(telegramBotToken) < 40) || (strlen(telegramChatId) < 7))
sendDataToMessengerEvery = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "Interval" instead of "Every"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s. above


c_telegram.wc = new WiFiClientSecure;
c_telegram.wc->setCACert(TELEGRAM_CERTIFICATE_ROOT);
c_telegram.hc = new HTTPClient;

if (sendDataToMessengerEvery >= 0) {
log(DEBUG, "Starting Telegram Bot...");
telegram_bot = new UniversalTelegramBot(telegramBotToken, *(c_telegram.wc));
}

set_status(STATUS_SCOMM, sendToCommunity ? ST_SCOMM_INIT : ST_SCOMM_OFF);
set_status(STATUS_MADAVI, sendToMadavi ? ST_MADAVI_INIT : ST_MADAVI_OFF);
set_status(STATUS_TTN, sendToLora ? ST_TTN_INIT : ST_TTN_OFF);
set_status(STATUS_TELEGRAM, (sendDataToMessengerEvery >= 0) ? ST_TELEGRAM_INIT : ST_TELEGRAM_OFF);
}

void poll_transmission() {
Expand Down Expand Up @@ -142,7 +157,7 @@ int send_http_geiger(HttpsClient *client, const char *host, unsigned int timedif
int send_http_thp(HttpsClient *client, const char *host, float temperature, float humidity, float pressure, int xpin) {
char body[1000];
prepare_http(client, host);
if(xpin != XPIN_NO_XPIN) {
if (xpin != XPIN_NO_XPIN) {
client->hc->addHeader("X-PIN", String(xpin));
}
const char *json_format = R"=====(
Expand Down Expand Up @@ -257,7 +272,7 @@ void transmit_data(String tube_type, int tube_nbr, unsigned int dt, unsigned int
log(INFO, "Sent to CUSTOMSRV, status: %s, http: %d %d", customsrv_ok ? "ok" : "error", rc1, rc2);
#endif

if(sendToMadavi && (wifi_status == ST_WIFI_CONNECTED)) {
if (sendToMadavi && (wifi_status == ST_WIFI_CONNECTED)) {
bool madavi_ok;
log(INFO, "Sending to Madavi ...");
set_status(STATUS_MADAVI, ST_MADAVI_SENDING);
Expand All @@ -271,7 +286,7 @@ void transmit_data(String tube_type, int tube_nbr, unsigned int dt, unsigned int
display_status();
}

if(sendToCommunity && (wifi_status == ST_WIFI_CONNECTED)) {
if (sendToCommunity && (wifi_status == ST_WIFI_CONNECTED)) {
bool scomm_ok;
log(INFO, "Sending to sensor.community ...");
set_status(STATUS_SCOMM, ST_SCOMM_SENDING);
Expand All @@ -285,7 +300,7 @@ void transmit_data(String tube_type, int tube_nbr, unsigned int dt, unsigned int
display_status();
}

if(isLoraBoard && sendToLora && (strcmp(appeui, "") != 0)) { // send only, if we have LoRa credentials
if (isLoraBoard && sendToLora && (strcmp(appeui, "") != 0)) { // send only, if we have LoRa credentials
bool ttn_ok;
log(INFO, "Sending to TTN ...");
set_status(STATUS_TTN, ST_TTN_SENDING);
Expand All @@ -296,5 +311,59 @@ void transmit_data(String tube_type, int tube_nbr, unsigned int dt, unsigned int
set_status(STATUS_TTN, ttn_ok ? ST_TTN_IDLE : ST_TTN_ERROR);
display_status();
}

}

void transmit_userinfo(String tube_type, int tube_nbr, float tube_factor, unsigned int cpm, unsigned int accu_cpm, float accu_rate,
int have_thp, float temperature, float humidity, float pressure, int wifi_status, bool alarm_status) {
Comment on lines +317 to +318
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indenting seems not adjusted. int directly below String?


if (wifi_status != ST_WIFI_CONNECTED)
return;

// if we don't have a valid Messenger config, do not send to Messenger
if (sendDataToMessengerEvery < 0)
return;
Comment on lines +323 to +325
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either remove the empty line 322 or add another empty line after 325 to get consistent?

// in case the config has been changed in the meantime
if ((strlen(telegramBotToken) < 40) || (strlen(telegramChatId) < 7)) {
sendDataToMessengerEvery = -1;
return;
}

static unsigned int transmitCounter = 0;
transmitCounter++;
if (transmitCounter == 27720) transmitCounter = 0; // 27720 % 1..12 == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure i understand...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aim was for the first numbers (i.e. 1 to 12) to avoid an hiccup (i.e. change in interval length) when the counter rolls over. As the actual time the sending is happening is slowly shifting anyway, it probably doesn't matter...
Can be resolved with a better timer handling, to avoid the dependency on the initial 2.5 min for sensor.community

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i still don't understand. and you need to add the comment to the source code, not here on github or in a year nobody will remember why we have that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will adapt to fixed interval after #444


char localEspId[16];
char thp_text[60];

chipID.toCharArray(localEspId, sizeof(localEspId));
if (have_thp) {
sprintf(thp_text, "\nBME data: %.1fC %.1f%% %.1fhPa", temperature, humidity, pressure/100);
}

if (((sendDataToMessengerEvery > 0) && (transmitCounter % sendDataToMessengerEvery == 0))
|| ((sendDataToMessengerEvery >= 0) && alarm_status)) {
Comment on lines +344 to +345
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be a triple use variable / in band signalling and that's bad:

  • it is the interval, if > 0
  • it means only send when alarm is on when 0
  • it means disabled when < 0

can we have different variables to make it better readable / configurable?

e.g. could be one for the interval and another one for the mode (disabled, always, only on alarm).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would maybe also solve the use case "send in intervals of N" but "only when alarm is on".

bool telegram_ok;
char message[120];
log(INFO, "Sending to Telegram messenger ...");
set_status(STATUS_TELEGRAM, ST_TELEGRAM_SENDING);
display_status();
if (alarm_status) {
if (tube_nbr > 0)
sprintf(message, "<b>--- MULTIGEIGER ALERT ! ---</b>\n<code>%s</code> rate too high:\n%.2f nSv/h (accumulated: %.2f nSv/h)", localEspId, cpm*tube_factor*1000/60, accu_rate*1000);
else
sprintf(message, "<b>--- MULTIGEIGER ALERT ! ---</b>\n<code>%s</code> rate too high:\n%d (accumulated: %d)", localEspId, cpm, accu_cpm);
Comment on lines +353 to +355
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no blank before the exclamation mark.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still todo.

also: the unit of measurement is missing for the lower case. "GM counts"?

} else {
if (tube_nbr > 0)
sprintf(message, "MultiGeiger <code>%s</code> rates:\n%.2f nSv/h (accumulated: %.2f nSv/h)%s", localEspId, cpm*tube_factor*1000/60, accu_rate*1000, have_thp ? thp_text : "");
else
sprintf(message, "MultiGeiger <code>%s</code> CPM:\n%d (accumulated: %d)%s", localEspId, cpm, accu_cpm, have_thp ? thp_text : "");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

}
telegram_ok = telegram_bot->sendMessage(telegramChatId, message, "HTML");
log(INFO, "Sent to Telegram messenger, status: %s", telegram_ok ? "ok" : "error");
set_status(STATUS_TELEGRAM, telegram_ok ? ST_TELEGRAM_IDLE : ST_TELEGRAM_ERROR);
display_status();
ThomasWaldmann marked this conversation as resolved.
Show resolved Hide resolved
}

}

2 changes: 2 additions & 0 deletions multigeiger/transmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
void setup_transmission(const char *version, char *ssid, bool lora);
void transmit_data(String tube_type, int tube_nbr, unsigned int dt, unsigned int hv_pulses, unsigned int gm_counts, unsigned int cpm,
int have_thp, float temperature, float humidity, float pressure, int wifi_status);
void transmit_userinfo(String tube_type, int tube_nbr, float tube_factor, unsigned int cpm, unsigned int accu_cpm, float accu_rate,
int have_thp, float temperature, float humidity, float pressure, int wifi_status, bool alarm_status);

// The Arduino LMIC wants to be polled from loop(). This takes care of that on LoRa boards.
void poll_transmission(void);
Expand Down
22 changes: 22 additions & 0 deletions multigeiger/userdefines-example.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,25 @@
// If current dose rate rises to (default) 3 times the accumulated dose rate, i.e. 0.3 µSv/h, trigger the local alarm.
// ! Requires a valid tube type to be set in order to calculate dose rate.
#define LOCAL_ALARM_FACTOR 3 // current / accumulated dose rate

// Send MultiGeiger info and alerts to Messaging services. Currently supported:
// - Telegram Messenger
// REQUIRES WIFI CONNECTION!
// Update via Messenger every N sensor.community messages (default 150 s / 2.5 min).
// Set to 0 to disable normal data transfer.
// 24 = 1/hour, 576 = 1/day, 4032 = 1/week, max: 27719 (~48 days)
#define SEND_DATA_TO_MESSENGER_EVERY 0

// Send local alerts via supported Messenger services.
// See above for more info on local alerts.
#define SEND_LOCAL_ALARM_TO_MESSENGER true

///// TELEGRAM MESSENGER
// To communicate with the Telegram Messenger on your phone you need to create a bot.
// Starting point: https://core.telegram.org/bots
// You will get a Bot token, please provide this via Web Config.
// Form: "XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
// Important: Start your bot channel with the command "/start" and receive the Chat ID.
// In order to get MultiGeiger messages to your specific chat, please provide this Chat ID via Web Config.
// Form: "123456789"
Comment on lines +99 to +105
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be either in the form the user will see or in the documentation?


28 changes: 27 additions & 1 deletion multigeiger/webconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ static bool isLoraBoard;
float localAlarmThreshold = LOCAL_ALARM_THRESHOLD;
int localAlarmFactor = (int)LOCAL_ALARM_FACTOR;

int sendDataToMessengerEvery = (int)SEND_DATA_TO_MESSENGER_EVERY;
bool sendLocalAlarmToMessenger = SEND_LOCAL_ALARM_TO_MESSENGER;
char telegramBotToken[50] = ""; // "XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
char telegramChatId[12] = ""; // "1234567890"

char sendLocalAlarmToMessenger_c[CHECKBOX_LEN];

iotwebconf::ParameterGroup grpMisc = iotwebconf::ParameterGroup("misc", "Misc. Settings");
iotwebconf::CheckboxParameter startSoundParam = iotwebconf::CheckboxParameter("Start sound", "startSound", playSound_c, CHECKBOX_LEN, playSound);
iotwebconf::CheckboxParameter speakerTickParam = iotwebconf::CheckboxParameter("Speaker tick", "speakerTick", speakerTick_c, CHECKBOX_LEN, speakerTick);
Expand All @@ -57,7 +64,7 @@ iotwebconf::TextParameter deveuiParam = iotwebconf::TextParameter("DEVEUI", "dev
iotwebconf::TextParameter appeuiParam = iotwebconf::TextParameter("APPEUI", "appeui", appeui, 17);
iotwebconf::TextParameter appkeyParam = iotwebconf::TextParameter("APPKEY", "appkey", appkey, 33);

iotwebconf::ParameterGroup grpAlarm = iotwebconf::ParameterGroup("alarm", "Local Alarm Setting");
iotwebconf::ParameterGroup grpAlarm = iotwebconf::ParameterGroup("alarm", "Local Alarm Settings");
iotwebconf::CheckboxParameter soundLocalAlarmParam = iotwebconf::CheckboxParameter("Enable local alarm sound", "soundLocalAlarm", soundLocalAlarm_c, CHECKBOX_LEN, soundLocalAlarm);
iotwebconf::FloatTParameter localAlarmThresholdParam =
iotwebconf::Builder<iotwebconf::FloatTParameter>("localAlarmThreshold").
Expand All @@ -71,6 +78,18 @@ iotwebconf::IntTParameter<int16_t> localAlarmFactorParam =
min(2).max(100).
step(1).placeholder("2..100").build();

iotwebconf::ParameterGroup grpMessenger = iotwebconf::ParameterGroup("messenger", "Messenger Settings");
iotwebconf::CheckboxParameter sendLocalAlarmToMessengerParam = iotwebconf::CheckboxParameter("Send local alarm via Messenger", "sendLocalAlarmToMessenger", sendLocalAlarmToMessenger_c, CHECKBOX_LEN, sendLocalAlarmToMessenger);
iotwebconf::IntTParameter<int16_t> sendDataToMessengerEveryParam =
iotwebconf::Builder<iotwebconf::IntTParameter<int16_t>>("sendDataToMessengerEvery").
label("Send data via Messenger every N x 2.5min\n(0=never,24=1/h,576=1/d,4032=1/week,max:27719)").
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoding this would need that we remember to change this place if we ever change the 2.5min elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. We need a better architecture for data processing handling... s. above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also write here "every N measurement intervals" or so and that solves this problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with that, one can't give specific values for 1/h, 1/d, 1/w though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s. above

defaultValue(sendDataToMessengerEvery).
min(0).max(27719).
step(1).placeholder("0..27719").build();
iotwebconf::PasswordParameter telegramBotTokenParam = iotwebconf::PasswordParameter("Telegram Bot Token (Reboot required!)", "telegramBotToken", telegramBotToken, 50);
iotwebconf::PasswordParameter telegramChatIdParam = iotwebconf::PasswordParameter("Telegram Chat ID", "telegramChatId", telegramChatId, 12);


// This only needs to be changed if the layout of the configuration is changed.
// Appending new variables does not require a new version number here.
// If this value is changed, ALL configuration variables must be re-entered,
Expand Down Expand Up @@ -162,6 +181,8 @@ void loadConfigVariables(void) {
soundLocalAlarm = soundLocalAlarmParam.isChecked();
localAlarmThreshold = localAlarmThresholdParam.value();
localAlarmFactor = localAlarmFactorParam.value();
sendDataToMessengerEvery = sendDataToMessengerEveryParam.value();
sendLocalAlarmToMessenger = sendLocalAlarmToMessengerParam.isChecked();
}

void configSaved(void) {
Expand Down Expand Up @@ -205,6 +226,11 @@ void setup_webconf(bool loraHardware) {
grpAlarm.addItem(&localAlarmThresholdParam);
grpAlarm.addItem(&localAlarmFactorParam);
iotWebConf.addParameterGroup(&grpAlarm);
grpMessenger.addItem(&sendDataToMessengerEveryParam);
grpMessenger.addItem(&sendLocalAlarmToMessengerParam);
grpMessenger.addItem(&telegramBotTokenParam);
grpMessenger.addItem(&telegramChatIdParam);
iotWebConf.addParameterGroup(&grpMessenger);

// if we don't have LoRa hardware, do not send to LoRa
if (!isLoraBoard)
Expand Down
5 changes: 5 additions & 0 deletions multigeiger/webconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ extern char appkey[];
extern float localAlarmThreshold;
extern int localAlarmFactor;

extern int sendDataToMessengerEvery;
extern char telegramBotToken[50];
extern char telegramChatId[15];
extern bool sendLocalAlarmToMessenger;

extern char ssid[];
extern IotWebConf iotWebConf;

Expand Down
1 change: 1 addition & 0 deletions platformio-example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ lib_deps=
IotWebConf@^3.1.0
MCCI LoRaWAN LMIC library
h2zero/NimBLE-Arduino
witnessmenow/UniversalTelegramBot@^1.3.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it required to fix it to that version?