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"
17#include "modules/microsd.hpp"
18#include "modules/power.hpp"
19#include "modules/wifi.hpp"
21
23static const uint8_t dev_addr = 0x20;
25static const int sda_pin = 0;
27static const int scl_pin = 1;
28
29const std::string ssid = "HARE_Lab";
30const std::string password = "";
31
32// create module handler
34
35// NOTE these variables must be relevant for the entire program lifetime
36// create wifi module
37static ModuleWiFi wifi;
38
39// create user config module
40static ModuleHandler::ModuleUserConfig user_config;
41
42// create and register the microSD module
43static ModuleMicroSD microSD;
44
45// commented out for now due to conflict with WiFi
46// static ModuleIrrigation irrigation;
47
48// power module
50
56void onReceive(int len) {
57 Log.traceln("onReceive(%d)", len);
58 mh.OnReceive(len);
59}
60
66void onRequest() {
67 Log.traceln("onRequest");
68 mh.OnRequest();
69 // power.EnterSleep();
70}
71
73void 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(&microSD);
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
135void loop() {
136 handleClient();
137 delay(20);
138}
Interface for the module handler.
void OnReceive(size_t num_bytes)
Arduino I2C onRecieve.
void RegisterModule(Module *module)
Register a module with a message type.
void OnRequest(void)
Arduino I2C onRequest.
MicroSD module for the esp32.
Definition microsd.hpp:32
WiFi module for the esp32.
Definition wifi.hpp:37
void handleClient()
Call to handle requests to the web server.
Module for controling irrigation valve.
void setup()
Definition main.cpp:73
void onReceive(int len)
Callback for onReceive.
Definition main.cpp:56
void onRequest()
Callback for onRequest.
Definition main.cpp:66
const std::string ssid
Definition main.cpp:29
const std::string password
Definition main.cpp:30
void loop()
Definition main.cpp:135
Module for accessing the microSD card.
Interface for controlling the esp32.
Module for controlling power on esp32.
Module for WiFi communication.