Lean on Arduino log library instead of custom logging methods (#546)

* Lean on Arduino log library instead of custom logging methods
This commit is contained in:
Florian authored and GitHub committed 2020-02-09 16:01:52 +01:00
1 parent 824346b19c
commit f3c9d6dd90
28 files changed
+557 -745

No files matched your search

+25 -33
View File
@@ -41,25 +41,21 @@ SMSmessage sms;
void setup2G()
{
trc(F("_2G_TX_PIN "));
trc(_2G_TX_PIN);
trc(F("_2G_RX_PIN "));
trc(_2G_RX_PIN);
Log.notice(F("_2G_TX_PIN: %d " CR), _2G_TX_PIN);
Log.notice(F("_2G_RX_PIN: %d " CR), _2G_RX_PIN);
setupGSM(false);
trc(F("Zgateway2G setup done "));
Log.trace(F("Zgateway2G setup done " CR));
}
void setupGSM(bool deleteSMS)
{
trc(F("Init 2G module: "));
trc(_2G_PWR_PIN);
Log.trace(F("Init 2G module: %d" CR), _2G_PWR_PIN);
delay(1000);
// Power-cycle the module to reset it.
A6l.powerCycle(_2G_PWR_PIN);
trc(F("waiting for network connection"));
Log.notice(F("waiting for network connection at bd: %d" CR), _2G_MODULE_BAUDRATE);
A6l.blockUntilReady(_2G_MODULE_BAUDRATE);
trc(F("A6/A7 gsm ready"));
Log.notice(F("A6/A7 gsm ready" CR));
signalStrengthAnalysis();
delay(1000);
// deleting all sms
@@ -67,11 +63,11 @@ void setupGSM(bool deleteSMS)
{
if (A6l.deleteSMS(1, 4) == A6_OK)
{
trc(F("delete SMS OK"));
Log.notice(F("delete SMS OK" CR));
}
else
{
trc(F("delete SMS KO"));
Log.error(F("delete SMS KO" CR));
}
}
}
@@ -80,11 +76,10 @@ void signalStrengthAnalysis()
{
int signalStrength = 0;
signalStrength = A6l.getSignalStrength();
trc(F("Signal strength: "));
trc(signalStrength);
Log.trace(F("Signal strength: %d" CR), signalStrength);
if (signalStrength < _2G_MIN_SIGNAL || signalStrength > _2G_MAX_SIGNAL)
{
trc(F("Signal too low restart the module"));
Log.trace(F("Signal too low restart the module" CR));
setupGSM(false); // if we are below or above a threshold signal we relaunch the setup of GSM module
}
}
@@ -93,19 +88,18 @@ bool _2GtoMQTT()
{
// Get the memory locations of unread SMS messages.
unreadSMSNum = A6l.getUnreadSMSLocs(unreadSMSLocs, 512);
trc(F("Creating SMS buffer"));
Log.trace(F("Creating SMS buffer" CR));
StaticJsonBuffer<JSON_MSG_BUFFER> jsonBuffer;
JsonObject &SMSdata = jsonBuffer.createObject();
for (int i = 0; i < unreadSMSNum; i++)
{
trc(F("New message at index: "));
trc(unreadSMSNum);
Log.notice(F("New message at index: %d" CR), unreadSMSNum);
sms = A6l.readSMS(unreadSMSLocs[i]);
SMSdata.set("message", (char *)sms.message.c_str());
SMSdata.set("date", (char *)sms.date.c_str());
SMSdata.set("phone", (char *)sms.number.c_str());
A6l.deleteSMS(unreadSMSLocs[i]); // we delete the SMS received
trc(F("Adv data 2GtoMQTT"));
Log.trace(F("Adv data 2GtoMQTT" CR));
pub(subject2GtoMQTT, SMSdata);
return true;
}
@@ -120,7 +114,7 @@ void MQTTto2G(char *topicOri, char *datacallback)
if (cmpToMainTopic(topicOri, subjectMQTTto2G))
{
trc(F("MQTTto2G data analysis"));
Log.trace(F("MQTTto2G data analysis" CR));
// 2G DATA ANALYSIS
String phone_number = "";
int pos0 = topic.lastIndexOf(_2GPhoneKey);
@@ -128,26 +122,24 @@ void MQTTto2G(char *topicOri, char *datacallback)
{
pos0 = pos0 + strlen(_2GPhoneKey);
phone_number = topic.substring(pos0);
trc(F("MQTTto2G phone ok"));
trc(phone_number);
trc(F("MQTTto2G sms"));
trc(data);
Log.notice(F("MQTTto2G phone: %s" CR),(char *)phone_number.c_str());
Log.notice(F("MQTTto2G sms: %s" CR),(char *)data.c_str());
if (A6l.sendSMS(phone_number, data) == A6_OK)
{
trc(F("SMS OK"));
Log.notice(F("SMS OK" CR));
// Acknowledgement to the GTW2G topic
pub(subjectGTW2GtoMQTT, "SMS OK"); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}
else
{
trc(F("SMS KO"));
Log.error(F("SMS KO" CR));
// Acknowledgement to the GTW2G topic
pub(subjectGTW2GtoMQTT, "SMS KO"); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}
}
else
{
trc(F("MQTTto2G Fail reading phone number"));
Log.error(F("MQTTto2G Fail reading phone number" CR));
}
}
}
@@ -161,26 +153,26 @@ void MQTTto2G(char *topicOri, JsonObject &SMSdata)
{
const char *sms = SMSdata["message"];
const char *phone = SMSdata["phone"];
trc(F("MQTTto2G json data analysis"));
Log.trace(F("MQTTto2G json data analysis" CR));
if (sms && phone)
{
trc(F("MQTTto2G sms & phone ok"));
trc(sms);
Log.notice(F("MQTTto2G phone: %s" CR),phone);
Log.notice(F("MQTTto2G sms: %s" CR),sms);
if (A6l.sendSMS(String(phone), String(sms)) == A6_OK)
{
trc(F("SMS OK"));
Log.notice(F("SMS OK" CR));
// Acknowledgement to the GTW2G topic
pub(subjectGTW2GtoMQTT, "SMS OK"); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}
else
{
trc(F("SMS KO"));
Log.error(F("SMS KO" CR));
pub(subjectGTW2GtoMQTT, "SMS KO"); // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
}
}
else
{
trc(F("MQTTto2G failed json read"));
Log.error(F("MQTTto2G failed json read" CR));
}
}
}