Skip to content

Commit

Permalink
little refactoring; updated firmware.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
genemars committed Feb 2, 2019
1 parent fedd4f2 commit db8f889
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ add_custom_target(
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_executable(${PROJECT_NAME} ${SRC_LIST} src/io/IOManager.cpp src/io/IOManager.h src/net/HTTPServer.cpp src/net/HTTPServer.h src/net/NetManager.cpp src/net/NetManager.h src/io/Logger.cpp src/io/Logger.h src/scripting/ProgramEngine.cpp src/scripting/ProgramEngine.h src/io/env/LightSensor.cpp src/io/env/LightSensor.h src/io/env/DS18B20.cpp src/io/env/DS18B20.h src/service/api/APIRequest.cpp src/service/api/APIRequest.h src/TaskManager.cpp src/TaskManager.h src/Task.cpp src/Task.h src/net/MQTTServer.cpp src/net/MQTTServer.h src/net/mqtt/MQTTBrokerConfig.cpp src/net/mqtt/MQTTBrokerConfig.h src/io/rf/x10/X10Message.cpp src/io/rf/x10/X10Message.h src/io/sys/Diagnostics.cpp src/io/sys/Diagnostics.h src/io/IOEvent.h src/io/IOEventDomains.h src/io/IOEventPaths.h src/service/EventRouter.cpp src/service/EventRouter.h src/service/api/APIHandler.h src/service/api/X10Handler.cpp src/service/api/X10Handler.h src/Utility.cpp src/Utility.h src/service/api/HomeGenieHandler.cpp src/service/api/HomeGenieHandler.h)
add_executable(${PROJECT_NAME} ${SRC_LIST} src/io/IOManager.cpp src/io/IOManager.h src/net/HTTPServer.cpp src/net/HTTPServer.h src/net/NetManager.cpp src/net/NetManager.h src/io/Logger.cpp src/io/Logger.h src/scripting/ProgramEngine.cpp src/scripting/ProgramEngine.h src/io/env/LightSensor.cpp src/io/env/LightSensor.h src/io/env/DS18B20.cpp src/io/env/DS18B20.h src/service/api/APIRequest.cpp src/service/api/APIRequest.h src/TaskManager.cpp src/TaskManager.h src/Task.cpp src/Task.h src/net/MQTTServer.cpp src/net/MQTTServer.h src/net/mqtt/MQTTBrokerConfig.cpp src/net/mqtt/MQTTBrokerConfig.h src/io/rf/x10/X10Message.cpp src/io/rf/x10/X10Message.h src/io/sys/Diagnostics.cpp src/io/sys/Diagnostics.h src/io/IOEvent.h src/io/IOEventDomains.h src/io/IOEventPaths.h src/service/EventRouter.cpp src/service/EventRouter.h src/service/api/APIHandler.h src/service/api/X10Handler.cpp src/service/api/X10Handler.h src/Utility.cpp src/Utility.h src/service/api/HomeGenieHandler.cpp src/service/api/HomeGenieHandler.h src/service/defs.h)

include_directories(./.piolibdeps/ArduinoJson_ID64)
include_directories(./.piolibdeps/ArduinoLog_ID1532)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ based on the popular *ESP8266 chip*, a WiFi capable micro controller.

**Mobile client**

- HomeGenie plus for Android
- [HomeGenie plus](https://play.google.com/store/apps/details?id=com.glabs.homegenieplus&hl=en_US) for Android


### HomeGenie API
Expand Down Expand Up @@ -117,8 +117,8 @@ The PCB size is 44mm*50mm.

### Firmware

The firmware source code is built using *Platform.IO* and based on *Espressif*
platform and *Arduino* framework.
The firmware source code is built using [*Platform.IO IDE*](https://docs.platformio.org/en/latest/ide/pioide.html) and based on **Espressif**
platform and **Arduino** framework.

**Source code**

Expand Down
5 changes: 3 additions & 2 deletions src/io/env/DS18B20.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <io/IOEventPaths.h>
#include <io/Logger.h>
#include <io/IOEventDomains.h>
#include <service/defs.h>

#define DS18B20_NS_PREFIX "IO::Env::DS18B10"
#define DS18B20_SAMPLING_RATE 60000L
Expand All @@ -50,8 +51,8 @@ namespace IO { namespace Env {
DS18B20() {
setLoopInterval(DS18B20_SAMPLING_RATE);
// IEventSender members
domain = (const uint8_t *)(IOEventDomains::HomeAutomation_HomeGenie);
address = (const uint8_t *)"mini"; // TODO: declare "mini" as const
domain = (const uint8_t*)IOEventDomains::HomeAutomation_HomeGenie;
address = (const uint8_t*)HOMEGENIE_BUILTIN_MODULE_ADDRESS;
}
void begin();
void loop();
Expand Down
5 changes: 3 additions & 2 deletions src/io/env/LightSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <io/IOEventPaths.h>
#include <io/IOEvent.h>
#include <io/IOEventDomains.h>
#include <service/defs.h>

#define LIGHTSENSOR_NS_PREFIX "IO::Env::LightSensor"
#define LIGHTSENSOR_SAMPLING_RATE 5000L
Expand All @@ -46,8 +47,8 @@ namespace IO { namespace Env {
LightSensor() {
setLoopInterval(LIGHTSENSOR_SAMPLING_RATE);
// IEventSender members
domain = (const uint8_t *)(IOEventDomains::HomeAutomation_HomeGenie);
address = (const uint8_t *)"mini"; // TODO: delcare "mini" as const
domain = (const uint8_t*)IOEventDomains::HomeAutomation_HomeGenie;
address = (const uint8_t*)HOMEGENIE_BUILTIN_MODULE_ADDRESS;
}
void begin();
void loop();
Expand Down
3 changes: 2 additions & 1 deletion src/io/rf/x10/RFReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*
*/

#include <service/defs.h>
#include "RFReceiver.h"

namespace IO { namespace X10 {
Expand All @@ -41,7 +42,7 @@ namespace IO { namespace X10 {
receiverInstance = this;
// IEventSender members
domain = (const uint8_t *)(IOEventDomains::HomeAutomation_X10);
address = (const uint8_t *)"RF"; // TODO: declare "RF" as const
address = (const uint8_t *)HOMEGENIE_X10RF_MODULE_ADDRESS;
}

RFReceiver::RFReceiver(RFReceiverConfig *configuration) : RFReceiver() {
Expand Down
3 changes: 2 additions & 1 deletion src/io/sys/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
*
*/

#include <service/api/HomeGenieHandler.h>
#include "Diagnostics.h"

namespace IO { namespace System {

Diagnostics::Diagnostics() {
// IEventSender members
domain = (const uint8_t *)(IOEventDomains::HomeAutomation_HomeGenie);
address = (const uint8_t *)"mini";
address = (const uint8_t*)HOMEGENIE_BUILTIN_MODULE_ADDRESS;
// update interval
setLoopInterval(DIAGNOSTICS_SAMPLING_RATE);
}
Expand Down
2 changes: 1 addition & 1 deletion src/net/NetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Net {

HTTPServer httpServer;

// Time sync
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
// Variables to save date and time
Expand Down Expand Up @@ -141,7 +142,6 @@ namespace Net {

webSocket->loop();

// TODO: this "while" seem the only way to make NTPClient work
if (WiFi.isConnected() && !timeClient.update()) {
timeClient.forceUpdate();
// The formattedDate comes with the following format:
Expand Down
4 changes: 2 additions & 2 deletions src/service/HomeGenie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace Service {
auto temperatureSensor = getIOManager().getTemperatureSensor();
auto paramLuminance = HomeGenie::createModuleParameter("Sensor.Luminance", String(lightSensor.getLightLevel()).c_str(), currentTime.c_str());
auto paramTemperature = HomeGenie::createModuleParameter("Sensor.Temperature", String(temperatureSensor.getTemperature()).c_str(), currentTime.c_str());
return String(HomeGenie::createModule(IOEventDomains::HomeAutomation_HomeGenie, BUILTIN_MODULE_ADDRESS,
return String(HomeGenie::createModule(IOEventDomains::HomeAutomation_HomeGenie, HOMEGENIE_BUILTIN_MODULE_ADDRESS,
"HG-Mini", "HomeGenie Mini node", "Sensor",
(paramLuminance+","+paramTemperature).c_str()));
}
Expand All @@ -186,7 +186,7 @@ namespace Service {

int HomeGenie::writeModuleJSON(ESP8266WebServer *server, String &domain, String &address) {
auto outputCallback = APIHandlerOutputCallback(server);
if (domain == (IOEventDomains::HomeAutomation_HomeGenie) && address == BUILTIN_MODULE_ADDRESS) {
if (domain == (IOEventDomains::HomeAutomation_HomeGenie) && address == HOMEGENIE_BUILTIN_MODULE_ADDRESS) {
auto module = getBuiltinModuleJSON();
outputCallback.write(module);
// TODO: check out if `module` gets actually disposed
Expand Down
2 changes: 0 additions & 2 deletions src/service/api/HomeGenieHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <io/IOEventDomains.h>
#include <Utility.h>

#define BUILTIN_MODULE_ADDRESS "mini"

namespace Service { namespace API {

class APIHandlerOutputCallback : public OutputStreamCallback {
Expand Down
22 changes: 12 additions & 10 deletions src/service/api/X10Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Service { namespace API {
"DoorWindow"
};

X10Module moduleList[/*house codes*/ (16 + 1/*+1 is for sensors*/)][/*units*/ 16];
X10Module moduleList[/*house codes*/ (HOUSE_MAX-HOUSE_MIN+1)][/*units*/ UNIT_MAX];

void X10Handler::getModuleJSON(OutputStreamCallback *outputCallback, String &domain, String &address) {
address.toLowerCase();
Expand All @@ -79,10 +79,10 @@ namespace Service { namespace API {
auto domain = String((IOEventDomains::HomeAutomation_X10));
auto separator = String(",\n");
// X10 Home Automation modules
for (int h = 0; h < 16; h++) {
for (int h = HOUSE_MIN; h <= HOUSE_MAX; h++) {
for (int m = 0; m < UNIT_MAX; m++) {
auto address = String((char)((int)HOUSE_MIN+h))+String(m+UNIT_MIN);
if (h != 0 || m != 0) outputCallback->write(separator);
auto address = String((char)h)+String(m+UNIT_MIN);
if (h != HOUSE_MIN || m != 0) outputCallback->write(separator);
getModuleJSON(outputCallback, domain, address);
}
}
Expand All @@ -91,16 +91,18 @@ namespace Service { namespace API {
void X10Handler::getGroupListJSON(OutputStreamCallback *outputCallback) {
// TODO: Groups have to be managed from Service::HomeGenie class, read below:
// TODO: implement X10Handler::getGetModules() and move this code to HomeGenie::writeGroupListJSON(&server)
String line = R"([{"Name":"Dashboard","Modules":[{"Address":"mini","Domain":"HomeAutomation.HomeGenie"}]},)";
String line = R"([{"Name":"Dashboard","Modules":[{"Address":")";
line += HOMEGENIE_BUILTIN_MODULE_ADDRESS;
line += R"(","Domain":"HomeAutomation.HomeGenie"}]},)";
outputCallback->write(line);
line = R"({"Name":"X10 Modules", "Modules":[)";
outputCallback->write(line);
for (int h = 0; h < 16; h++) {
for (int h = 0; h <= (HOUSE_MAX-HOUSE_MIN); h++) {
for (int m = 0; m < UNIT_MAX; m++) {
line = R"({"Address":")" + String((char)('A'+h))+String(m + 1) + R"(","Domain":"HomeAutomation.X10"})";
outputCallback->write(line);
line = ",";
if (!(m == UNIT_MAX-1 && h == 16-1)) outputCallback->write(line);
if (!(m == UNIT_MAX-1 && h == (HOUSE_MAX-HOUSE_MIN))) outputCallback->write(line);
}
}
line = "]}]";
Expand All @@ -110,7 +112,7 @@ namespace Service { namespace API {
bool X10Handler::handleRequest(HomeGenie &homeGenie, APIRequest *command, ESP8266WebServer &server) {

if (command->Domain == (IOEventDomains::HomeAutomation_X10)
&& command->Address == "RF"
&& command->Address == HOMEGENIE_X10RF_MODULE_ADDRESS
&& command->Command == "Control.SendRaw") {

uint8_t data[command->OptionsString.length() / 2]; Utility::getBytes(command->OptionsString, data);
Expand All @@ -124,7 +126,7 @@ namespace Service { namespace API {
} else if (command->Domain == (IOEventDomains::HomeAutomation_X10)) {
uint8_t data[5];
auto hu = command->Address; hu.toLowerCase();
int h = (int)hu.charAt(0)-(int)HOUSE_MIN; // house code 0..15
int h = (int)hu.charAt(0) - (int)HOUSE_MIN; // house code 0..15
int u = hu.substring(1).toInt() - UNIT_MIN; // unit code 0..15
auto moduleStatus = &moduleList[h][u];

Expand Down Expand Up @@ -201,7 +203,7 @@ namespace Service { namespace API {
/*
* X10 RF Receiver "Sensor.RawData" event
*/
if (address == "RF" /* TODO: declare "RF" as const */ && event == (IOEventPaths::Sensor_RawData) /*&& ioManager.getX10Receiver().isEnabled()*/) {
if (address == HOMEGENIE_X10RF_MODULE_ADDRESS && event == (IOEventPaths::Sensor_RawData) /*&& ioManager.getX10Receiver().isEnabled()*/) {
// decode event data (X10 RF packet)
auto data = ((uint8_t *) eventData);
/// \param type Type of message (eg. 0x20 = standard, 0x29 = security, ...)
Expand Down
11 changes: 11 additions & 0 deletions src/service/defs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Created by gene on 01/02/19.
//

#ifndef HOMEGENIE_MINI_DEFS_H
#define HOMEGENIE_MINI_DEFS_H

#define HOMEGENIE_BUILTIN_MODULE_ADDRESS "mini"
#define HOMEGENIE_X10RF_MODULE_ADDRESS "RF"

#endif //HOMEGENIE_MINI_DEFS_H

0 comments on commit db8f889

Please sign in to comment.