-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.cpp
101 lines (83 loc) · 2.6 KB
/
log.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <WiFi.h>
#include "esp_heap_caps.h"
#include "TelnetSerialStream.h"
#include "global.h"
#include "rfid.h"
#include "log.h"
TelnetSerialStream telnetSerialStream = TelnetSerialStream();
#ifdef SYSLOG_HOST
#include "SyslogStream.h"
SyslogStream syslogStream = SyslogStream();
#endif
#ifdef MQTT_HOST
#include "MqttlogStream.h"
// EthernetClient client;
WiFiClient client;
MqttStream mqttStream = MqttStream(&client);
char topic[128] = "debug/log/" TERMINAL_NAME;
#endif
TLog Log, Debug;
void setupLog() {
const std::shared_ptr<LOGBase> telnetSerialStreamPtr = std::make_shared<TelnetSerialStream>(telnetSerialStream);
Log.addPrintStream(telnetSerialStreamPtr);
Debug.addPrintStream(telnetSerialStreamPtr);
#ifdef SYSLOG_HOST
syslogStream.setDestination(SYSLOG_HOST);
syslogStream.setRaw(false); // wether or not the syslog server is a modern(ish) unix.
#ifdef SYSLOG_PORT
syslogStream.setPort(SYSLOG_PORT);
#endif
const std::shared_ptr<LOGBase> syslogStreamPtr = std::make_shared<SyslogStream>(syslogStream);
Log.addPrintStream(syslogStreamPtr);
#endif
#ifdef MQTT_HOST
#ifdef MQTT_TOPIC_PREFIX
snprintf(topic, sizeof(topic), "%s/log/%s", MQTT_TOPIC_PREFIX, terminalName);
#endif
mqttStream.setServer(MQTT_HOST);
mqttStream.setTopic(topic);
const std::shared_ptr<LOGBase> mqttStreamPtr = std::make_shared<MqttStream>(mqttStream);
Log.addPrintStream(mqttStreamPtr);
#endif
Log.begin();
Debug.begin();
}
#ifdef ESP32
#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
static double coreTemp() {
double temp_farenheit = temprature_sens_read();
return ( temp_farenheit - 32. ) / 1.8;
}
#endif
void log_loop() {
static unsigned long last_report = millis();
static unsigned long cntr;
Log.loop();
Debug.loop();
cntr++;
if (millis() - last_report < REPORT_INTERVAL)
return;
double lr = 1000. * cntr / (millis() - last_report);
Debug.printf("Loop rate %.1f [#/second]\n", lr);
Log.printf("%s {\"rfid_scans\":%u,\"rfid_miss\":%u,"\
"\"ota\":true,\"state\":3,\"IP\":\"%s\","\
"\"MAC\":\"%s\",\"paid\":%.2f,\"version\":\"%s\"," \
"\"firmware\":\"%s\",\"heap\":%u,\"coreTemp\": %.1f,"
"\"loopRate\":%.1f,"
"\"stationName\":%s,"
"\"}\n",
stationname, rfid_scans, rfid_miss,
WiFi.localIP().toString().c_str(),
String(WiFi.macAddress()).c_str(), paid,
VERSION, terminalName,
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
coreTemp(), lr, stationname);
cntr = 0;
last_report = millis();
};