ENTS-tock
Environmental NeTworked Sensor firmware on Tock OS
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
8
#include <Arduino.h>
9
#include <ArduinoLog.h>
10
#include <LittleFS.h>
11
#include <WiFi.h>
12
#include <Wire.h>
13
14
#include "
config_server.hpp
"
15
#include "
module_handler.hpp
"
16
#include "
modules/irrigation.hpp
"
17
#include "
modules/microsd.hpp
"
18
#include "
modules/power.hpp
"
19
#include "
modules/wifi.hpp
"
20
#include "
modules/wifi_userconfig.hpp
"
21
23
static
const
uint8_t dev_addr = 0x20;
25
static
const
int
sda_pin = 0;
27
static
const
int
scl_pin = 1;
28
29
const
std::string
ssid
=
"HARE_Lab"
;
30
const
std::string
password
=
""
;
31
32
// create module handler
33
static
ModuleHandler::ModuleHandler
mh;
34
35
// NOTE these variables must be relevant for the entire program lifetime
36
// create wifi module
37
static
ModuleWiFi
wifi;
38
39
// create user config module
40
static
ModuleHandler::ModuleUserConfig
user_config;
41
42
// create and register the microSD module
43
static
ModuleMicroSD
microSD;
44
45
// commented out for now due to conflict with WiFi
46
// static ModuleIrrigation irrigation;
47
48
// power module
49
static
ModuleHandler::ModulePower
power;
50
56
void
onReceive
(
int
len) {
57
Log.traceln(
"onReceive(%d)"
, len);
58
mh.
OnReceive
(len);
59
}
60
66
void
onRequest
() {
67
Log.traceln(
"onRequest"
);
68
mh.
OnRequest
();
69
// power.EnterSleep();
70
}
71
73
void
setup
() {
74
// Start serial interface
75
Serial.begin(115200);
76
77
// Create logging interfface
78
Log.begin(LOG_LEVEL_TRACE, &Serial);
79
80
if
(!LittleFS.begin()) {
81
Log.errorln(
"LittleFS mount failed!"
);
82
return
;
83
}
84
85
/*
86
// Needed for irrigation
87
// WiFi.begin(ssid.c_str(), password.c_str());
88
89
while (WiFi.status() != WL_CONNECTED) {
90
delay(500);
91
Serial.print(".");
92
}
93
94
Serial.println("");
95
Serial.println("WiFi connected");
96
Serial.println("IP address: ");
97
Serial.println(WiFi.localIP());
98
99
// Setup Web server
100
SetupServer();
101
102
Log.noticeln("Web server started");
103
// Log.noticeln("Connect to ESP32 AP and visit http://%s",
104
// WiFi.softAPIP().toString().c_str());
105
*/
106
107
Log.noticeln(
"ents-node esp32 firmware, compiled at %s %s"
, __DATE__,
108
__TIME__);
109
Log.noticeln(
"Git SHA: %s"
, GIT_REV);
110
111
mh.
RegisterModule
(&wifi);
112
113
mh.
RegisterModule
(µSD);
114
115
mh.
RegisterModule
(&user_config);
116
117
// commented out for now due to conflict with WiFi
118
// mh.RegisterModule(&irrigation);
119
120
mh.
RegisterModule
(&power);
121
122
// start i2c interface
123
Wire.onReceive(
onReceive
);
124
Wire.onRequest(
onRequest
);
125
bool
i2c_status = Wire.begin(dev_addr, sda_pin, scl_pin, 400000);
126
127
if
(i2c_status) {
128
Log.noticeln(
"Success!"
);
129
}
else
{
130
Log.noticeln(
"Failed!"
);
131
}
132
}
133
135
void
loop
() {
136
handleClient
();
137
delay(20);
138
}
ModuleHandler::ModuleHandler
Interface for the module handler.
Definition
module_handler.hpp:53
ModuleHandler::ModuleHandler::OnReceive
void OnReceive(size_t num_bytes)
Arduino I2C onRecieve.
Definition
module_handler.cpp:25
ModuleHandler::ModuleHandler::RegisterModule
void RegisterModule(Module *module)
Register a module with a message type.
Definition
module_handler.cpp:14
ModuleHandler::ModuleHandler::OnRequest
void OnRequest(void)
Arduino I2C onRequest.
Definition
module_handler.cpp:113
ModuleHandler::ModulePower
Definition
power.hpp:30
ModuleHandler::ModuleUserConfig
Definition
wifi_userconfig.hpp:12
ModuleMicroSD
MicroSD module for the esp32.
Definition
microsd.hpp:32
ModuleWiFi
WiFi module for the esp32.
Definition
wifi.hpp:37
config_server.hpp
handleClient
void handleClient()
Call to handle requests to the web server.
Definition
config_server.cpp:260
irrigation.hpp
Module for controling irrigation valve.
setup
void setup()
Definition
main.cpp:73
onReceive
void onReceive(int len)
Callback for onReceive.
Definition
main.cpp:56
onRequest
void onRequest()
Callback for onRequest.
Definition
main.cpp:66
ssid
const std::string ssid
Definition
main.cpp:29
password
const std::string password
Definition
main.cpp:30
loop
void loop()
Definition
main.cpp:135
microsd.hpp
Module for accessing the microSD card.
module_handler.hpp
Interface for controlling the esp32.
power.hpp
Module for controlling power on esp32.
wifi.hpp
Module for WiFi communication.
wifi_userconfig.hpp
embedded
esp32
src
main.cpp
Generated by
1.9.8