STIMA  3
stimawifi.h
1 #include "common.h"
2 
3 #ifndef STIMAWIFI_H_
4 #define STIMAWIFI_H_
5 
6 const char* update_url = "/firmware/update/" FIRMWARE_TYPE "/";
7 const uint16_t update_port = 80;
8 
9 WiFiManager wifiManager;
10 WebServer webserver(STIMAHTTP_PORT);
11 
12 WiFiClient httpClient;
13 WiFiClient networkClient;
14 //EspHtmlTemplateProcessor templateProcessor(&server);
15 MutexStandard loggingmutex;
16 MutexStandard i2cmutex;
17 MutexStandard geomutex;
18 
19 #if (ENABLE_SDCARD_LOGGING)
20 
25 File logFile;
26 
31 WriteLoggingStream loggingStream(logFile,Serial);
32 #endif
33 
34 //flag for saving data
35 bool shouldSaveConfig = false;
36 bool pmspresent = false;
37 
38 U8G2_SSD1306_64X48_ER_F_HW_I2C u8g2(U8G2_R0);
39 bool oledpresent=false;
40 
41 // i2c button for wemos OLED version 2.1.0
42 I2C_BUTTON button; //I2C address 0x31
43 // I2C_BUTTON button(DEFAULT_I2C_BUTTON_ADDRESS); //I2C address 0x31
44 
45 summarydata_t summarydata;
46 
47 georef_t georef={"","",0,&geomutex};
48 
49 
50 /*
51 If the variable can be updated atomically (for example it is not a
52 32-bit variable on a 16-bit architecture, which would take two writes to
53 update all 32-bits), and there is only one task that ever writes to the
54 variable (although many can read from it), then a global variable should
55 not cause a problem.
56 This is the case for stimawifiStatus
57 */
58 stimawifiStatus_t stimawifiStatus;
59 station_t station;
60 
61 udp_data_t udp_data={1,&frtosLog,&stimawifiStatus.udp,&georef};
62 udpThread threadUdp(&udp_data);
63 
64 gps_data_t gps_data={1,&frtosLog,&stimawifiStatus.gps,&georef};
65 gpsThread threadGps(&gps_data);
66 
67 Queue dbQueue(DB_QUEUE_LEN,sizeof(mqttMessage_t)); // ~ 1 minutes queue
68 Queue mqttQueue(MQTT_QUEUE_LEN,sizeof(mqttMessage_t)); // ~ 1.5 minutes queue
69 BinaryQueue recoveryQueue(sizeof(rpcRecovery_t));
70 BinarySemaphore recoverySemaphore(false);
71 db_data_t db_data={1,&frtosLog,&dbQueue,&mqttQueue,&recoverySemaphore,&recoveryQueue,&stimawifiStatus.db,&station};
72 dbThread threadDb(&db_data);
73 
74 measure_data_t measure_data={1,&frtosLog,&mqttQueue,&dbQueue,&stimawifiStatus.measure,&station,&summarydata,&i2cmutex,&georef};
75 measureThread threadMeasure(&measure_data);
76 
77 publish_data_t publish_data={1,&frtosLog,&mqttQueue,&dbQueue,&recoveryQueue,&stimawifiStatus.publish,&station,&networkClient};
78 publishThread threadPublish(&publish_data);
79 
80 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, LED_PIN, NEO_GRB + NEO_KHZ800);
81 
82 char status[15]=""; // status message for web and display
83 
84 
85 String Json();
86 String Data();
87 String FullPage();
88 void writeconfig();
89 
90 // web server response function
91 void handle_FullPage();
92 void handle_Data();
93 void handle_Json();
94 void handle_NotFound();
95 //callback notifying us of the need to save config
96 void saveConfigCallback ();
97 String rmap_get_remote_config();
98 void firmware_upgrade();
99 String readconfig_rmap();
100 void writeconfig_rmap(const String payload);
101 int rmap_config(const String payload);
102 void readconfig();
103 void writeconfig();
104 void web_values(const char* values);
105 void measureAndPublish();
106 void reboot();
107 void logPrefix(Print* _logOutput);
108 void logSuffix(Print* _logOutput);
109 void setup();
110 void loop();
111 
112 #endif
Definition: db_thread.h:19
Definition: gps_thread.h:24
Definition: measure_thread.h:26
Definition: publish_thread.h:26
Definition: udp_thread.h:28
void setup()
Arduino setup function. Init watchdog, hardware, debug, buffer and load configuration stored in EEPRO...
Definition: i2c-leaf.ino:31
void loop()
Arduino loop function. First, initialize tasks and sensors, then execute the tasks and activates the ...
Definition: i2c-leaf.ino:54
int reboot(JsonObject &params, JsonObject &result)
RPC reboot.
Definition: db_thread.h:5
Definition: typedef.h:58
Definition: gps_thread.h:15
Definition: measure_thread.h:6
Definition: typedef.h:134
Definition: publish_thread.h:10
Definition: typedef.h:214
Definition: typedef.h:70
Definition: typedef.h:200
udpStatus_t udp
Stati relativi al thread di ricezione UDP dei dati di georeferenziazione.
Definition: typedef.h:203
measureStatus_t measure
Stati relativi al thread di misura.
Definition: typedef.h:201
publishStatus_t publish
Stati relativi al thread di pubblicazione.
Definition: typedef.h:202
dbStatus_t db
Stati relativi al thread di gestione del DataBase.
Definition: typedef.h:205
gpsStatus_t gps
Stati relativi al thread di ricezione GPS (porta seriale) dei dati di georeferenziazione.
Definition: typedef.h:204
Definition: typedef.h:29
Definition: udp_thread.h:19