Sming 3.8.0 update
parent
24924811b2
commit
517ceea15c
|
@ -33,7 +33,7 @@ void SpejsNode::systemReady() {
|
|||
registerEndpoint("$implementation", new ImplementationEndpoint());
|
||||
|
||||
// Keepalive Timer initialization
|
||||
keepaliveTimer.initializeMs(10000, TimerDelegate(&SpejsNode::keepAliveHandler, this)).start();
|
||||
keepaliveTimer.initializeMs(10000, [=]() { keepAliveHandler(); }).start();
|
||||
|
||||
statusLED.high();
|
||||
}
|
||||
|
@ -147,18 +147,30 @@ void SpejsNode::onConnected() {
|
|||
|
||||
debugf("Connection successful");
|
||||
|
||||
mqtt.setMessageHandler([=](MqttClient& client, mqtt_message_t* message) -> int {
|
||||
if (message == nullptr) return -1;
|
||||
|
||||
String topic = String((const char*)message->publish.topic_name.data, message->publish.topic_name.length);
|
||||
String content;
|
||||
if(message->publish.content.data) {
|
||||
content.concat((const char*)message->publish.content.data, message->publish.content.length);
|
||||
}
|
||||
|
||||
mqttCallback(topic, content);
|
||||
return 0;
|
||||
});
|
||||
|
||||
// MQTT initialization
|
||||
mqtt.setWill(DEV_TOPIC("$online"), "false", 1, true);
|
||||
|
||||
#ifdef ENABLE_SSL
|
||||
const uint8_t sha1Fingerprint[] = SSL_FINGERPRINT;
|
||||
mqtt.connect("iot-" + deviceID, "", "", true);
|
||||
mqtt.addSslOptions(SSL_SERVER_VERIFY_LATER);
|
||||
mqtt.setSslFingerprint(sha1Fingerprint, 20);
|
||||
#else
|
||||
mqtt.connect("iot-" + deviceID);
|
||||
#endif
|
||||
|
||||
mqtt.connect(brokerURL, "iot-" + deviceID);
|
||||
|
||||
for(unsigned int i = 0 ; i < endpoints.count() ; i++) {
|
||||
endpoints.valueAt(i)->onConnected();
|
||||
}
|
||||
|
@ -177,9 +189,9 @@ void SpejsNode::onConnected() {
|
|||
|
||||
// HTTP initialization
|
||||
http.listen(80);
|
||||
http.addPath("/", HttpPathDelegate(&SpejsNode::httpIndex, this));
|
||||
http.addPath("/config.json", HttpPathDelegate(&SpejsNode::httpConfig, this));
|
||||
http.setDefaultHandler(HttpPathDelegate(&SpejsNode::httpFile, this));
|
||||
http.paths.set("/", HttpPathDelegate(&SpejsNode::httpIndex, this));
|
||||
http.paths.set("/config.json", HttpPathDelegate(&SpejsNode::httpConfig, this));
|
||||
http.paths.setDefault(HttpPathDelegate(&SpejsNode::httpFile, this));
|
||||
http.setBodyParser("application/json", bodyToStringParser);
|
||||
}
|
||||
|
||||
|
@ -198,7 +210,7 @@ void SpejsNode::httpConfig(HttpRequest &request, HttpResponse &response)
|
|||
|
||||
void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response)
|
||||
{
|
||||
String file = request.getPath();
|
||||
String file = request.uri.Path;
|
||||
|
||||
if (file[0] == '/')
|
||||
file = file.substring(1);
|
||||
|
@ -215,7 +227,7 @@ void SpejsNode::httpFile(HttpRequest &request, HttpResponse &response)
|
|||
JsonObjectStream* stream = new JsonObjectStream();
|
||||
JsonObject& json = stream->getRoot();
|
||||
json["status"] = result.status;
|
||||
response.sendJsonObject(stream);
|
||||
response.sendDataStream(stream, MIME_JSON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
highState = highState_;
|
||||
|
||||
pinMode(pin, OUTPUT);
|
||||
animateTimer.initializeMs(50, TimerDelegate(&LED::animate, this)).start();
|
||||
animateTimer.initializeMs(50, [=]() { animate(); }).start();
|
||||
}
|
||||
|
||||
void idle() {
|
||||
|
@ -89,7 +89,6 @@ public:
|
|||
uint8_t currentSlot;
|
||||
|
||||
SpejsNode(String _deviceType) :
|
||||
mqtt(MQTT_BROKER, MQTT_PORT, MqttStringSubscriptionCallback(&SpejsNode::mqttCallback, this)),
|
||||
deviceType(_deviceType) {};
|
||||
|
||||
void onConnected();
|
||||
|
|
|
@ -4,7 +4,7 @@ void DHTEndpoint::bind(String _name, SpejsNode* _parent) {
|
|||
Endpoint::bind(_name, _parent);
|
||||
|
||||
sensor.setup(pin, sensor_type);
|
||||
samplingTimer.initializeMs(samplingRate, TimerDelegate(&DHTEndpoint::sample, this)).start();
|
||||
samplingTimer.initializeMs(samplingRate, [=]() { sample(); }).start();
|
||||
}
|
||||
|
||||
void DHTEndpoint::sample() {
|
||||
|
|
|
@ -18,7 +18,7 @@ protected:
|
|||
|
||||
public:
|
||||
DHTEndpoint(int _pin, int _samplingRate = 10000, DHTesp::DHT_MODEL_t _sensor_type=DHTesp::DHT11) :
|
||||
ValueEndpoint("dht"), pin(_pin), sensor_type(_sensor_type),
|
||||
ValueEndpoint("dht"), sensor_type(_sensor_type), pin(_pin),
|
||||
samplingRate(_samplingRate) {}
|
||||
|
||||
void bind(String name, SpejsNode* _parent);
|
||||
|
|
Loading…
Reference in New Issue