More or less consistent .editorconfig
parent
21750d32d7
commit
81306827ad
|
@ -0,0 +1,12 @@
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Unix-style newlines with a newline ending every file
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
|
||||||
|
[*.{c,h,cpp}]
|
||||||
|
indent_style = spaces
|
||||||
|
indent_size = 4
|
|
@ -8,7 +8,7 @@ void Endpoint::bind(String _key, SpejsNode* _parent) {
|
||||||
|
|
||||||
void Endpoint::notify(String value) {
|
void Endpoint::notify(String value) {
|
||||||
/*if(parent)
|
/*if(parent)
|
||||||
parent->notify(this, value);*/
|
parent->notify(this, value);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void ValueEndpoint<T>::updateValue(T newValue) {
|
template <class T> void ValueEndpoint<T>::updateValue(T newValue) {
|
||||||
|
@ -65,12 +65,12 @@ void DHTEndpoint::bind(String _key, SpejsNode* _parent) {
|
||||||
void DHTEndpoint::sample() {
|
void DHTEndpoint::sample() {
|
||||||
TempAndHumidity th;
|
TempAndHumidity th;
|
||||||
if(sensor.readTempAndHumidity(th))
|
if(sensor.readTempAndHumidity(th))
|
||||||
{
|
{
|
||||||
updateValue(th.temp);
|
updateValue(th.temp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.print("Failed to read from DHT: ");
|
Serial.print("Failed to read from DHT: ");
|
||||||
Serial.print(sensor.getLastError());
|
Serial.print(sensor.getLastError());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,11 +48,11 @@ private:
|
||||||
bool currentValue;
|
bool currentValue;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OutputEndpoint(int _pin, bool _inverted = false) :
|
OutputEndpoint(int _pin, bool _inverted = false) : Endpoint("output"),
|
||||||
Endpoint("output"), pin(_pin), inverted(_inverted), currentValue(inverted) {
|
pin(_pin), inverted(_inverted), currentValue(inverted) {
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
digitalWrite(pin, currentValue);
|
digitalWrite(pin, currentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndpointResult onValue(String key, String value);
|
EndpointResult onValue(String key, String value);
|
||||||
void fillValue(JsonObject& obj);
|
void fillValue(JsonObject& obj);
|
||||||
|
|
|
@ -21,12 +21,11 @@ void SpejsNode::init() {
|
||||||
WifiStation.config(WIFI_SSID, WIFI_PWD);
|
WifiStation.config(WIFI_SSID, WIFI_PWD);
|
||||||
|
|
||||||
WifiStation.waitConnection(
|
WifiStation.waitConnection(
|
||||||
ConnectionDelegate(&SpejsNode::onConnected, this),
|
ConnectionDelegate(&SpejsNode::onConnected, this), 20, *[] {
|
||||||
20, *[] {
|
Serial.println("Connection failed");
|
||||||
Serial.println("Connection failed");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
registerEndpoint("control", new ControlEndpoint());
|
registerEndpoint("control", new ControlEndpoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpejsNode::keepAliveHandler() {
|
void SpejsNode::keepAliveHandler() {
|
||||||
|
@ -50,7 +49,7 @@ void SpejsNode::keepAliveHandler() {
|
||||||
|
|
||||||
void SpejsNode::httpIndex(HttpRequest &request, HttpResponse &response)
|
void SpejsNode::httpIndex(HttpRequest &request, HttpResponse &response)
|
||||||
{
|
{
|
||||||
response.sendString("This is spejsiot device, take a look at: https://wiki.hackerspace.pl/projects:spejsiot");
|
response.sendString("This is spejsiot device, take a look at: https://wiki.hackerspace.pl/projects:spejsiot");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpejsNode::buildMetadata(JsonObjectStream* stream)
|
void SpejsNode::buildMetadata(JsonObjectStream* stream)
|
||||||
|
@ -180,8 +179,8 @@ bool SpejsNode::notify(String key, String value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpejsNode::registerEndpoint(String key, Endpoint* endpoint) {
|
void SpejsNode::registerEndpoint(String key, Endpoint* endpoint) {
|
||||||
endpoints[key] = endpoint;
|
endpoints[key] = endpoint;
|
||||||
endpoint->bind(key, this);
|
endpoint->bind(key, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpejsNode::mqttCallback(String origtopic, String value) {
|
void SpejsNode::mqttCallback(String origtopic, String value) {
|
||||||
|
|
|
@ -30,8 +30,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
SpejsNode(String _deviceType) :
|
SpejsNode(String _deviceType) :
|
||||||
mqtt(MQTT_BROKER, MQTT_PORT, MqttStringSubscriptionCallback(&SpejsNode::mqttCallback, this)),
|
mqtt(MQTT_BROKER, MQTT_PORT, MqttStringSubscriptionCallback(&SpejsNode::mqttCallback, this)),
|
||||||
deviceType(_deviceType)
|
deviceType(_deviceType) {};
|
||||||
{};
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
SpejsNode node("switch");
|
SpejsNode node("switch");
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
node.init();
|
node.init();
|
||||||
node.registerEndpoint("relay", new OutputEndpoint(5));
|
node.registerEndpoint("relay", new OutputEndpoint(5));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue