Initial
This commit is contained in:
84
src/teleinsektarij.ino
Normal file
84
src/teleinsektarij.ino
Normal file
@ -0,0 +1,84 @@
|
||||
#include "hw.h"
|
||||
#include "comm.h"
|
||||
#include "measure.h"
|
||||
#include "dht_measure.h"
|
||||
#include "defs.h"
|
||||
#include "disp.h"
|
||||
|
||||
unsigned long timestamp_blink = 0;
|
||||
unsigned long timestamp_http_request = 0;
|
||||
unsigned long timestamp_ds_measure = 0;
|
||||
unsigned long timestamp_dht_measure = 0;
|
||||
bool first_loop = true;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
init_hw();
|
||||
|
||||
#ifdef SERIAL_DEBUG
|
||||
Serial.begin(SERIAL_BAUD_RATE);
|
||||
Serial.setDebugOutput(true);
|
||||
#endif
|
||||
|
||||
init_comm();
|
||||
init_measure();
|
||||
init_disp();
|
||||
|
||||
first_loop = true;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
unsigned long current_millis = millis();
|
||||
|
||||
// connect WiFi
|
||||
connect_comm();
|
||||
|
||||
if (first_loop)
|
||||
{
|
||||
// don't allow sending data to server in the first loop
|
||||
timestamp_http_request = current_millis;
|
||||
first_loop = false;
|
||||
}
|
||||
|
||||
// indicate program run
|
||||
if (current_millis - timestamp_blink > SIGNAL_LED_BLINK_INTERVAL)
|
||||
{
|
||||
blink_led(LED_BLUE, 50);
|
||||
delay(50);
|
||||
blink_led(LED_BLUE, 50);
|
||||
timestamp_blink = current_millis;
|
||||
}
|
||||
|
||||
if (current_millis - timestamp_ds_measure > DS_MEASURE_INTERVAL)
|
||||
{
|
||||
measure_next_sensor();
|
||||
timestamp_ds_measure = current_millis;
|
||||
}
|
||||
|
||||
if (current_millis - timestamp_dht_measure > DHT_MEASURE_INTERVAL)
|
||||
{
|
||||
dht_read_next_sensor();
|
||||
timestamp_dht_measure = current_millis;
|
||||
}
|
||||
|
||||
// post data to server
|
||||
if (comm_is_connected() && current_millis - timestamp_http_request > SEND_DATA_TO_SERVER_INTERVAL)
|
||||
{
|
||||
post_data_to_server();
|
||||
timestamp_http_request = current_millis;
|
||||
}
|
||||
|
||||
handle_disp();
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user