Skip to content

Commit

Permalink
fix for homieiot#477 and Homie Button Config in arduino SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
timpur committed Feb 22, 2018
1 parent 02a054a commit 57ecb0d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/Homie.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef SRC_HOMIE_H_
#define SRC_HOMIE_H_

#include "HomieFirmwareConfig.h"
#include "Homie.hpp"

#endif // SRC_HOMIE_H_
24 changes: 14 additions & 10 deletions src/Homie/Boot/BootConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,9 @@ void BootConfig::_onConfigRequest(AsyncWebServerRequest *request) {
return;
}

StaticJsonBuffer<MAX_JSON_CONFIG_ARDUINOJSON_FILE_BUFFER_SIZE> jsonBuffer;
const char* body = (const char*)(request->_tempObject);

StaticJsonBuffer<MAX_JSON_CONFIG_ARDUINOJSON_FILE_BUFFER_SIZE> jsonBuffer;
JsonObject& parsedJson = jsonBuffer.parseObject(body);

ValidationResult configWriteResult = Interface::get().getConfig().write(parsedJson);
Expand Down Expand Up @@ -455,15 +456,18 @@ void BootConfig::__setCORS() {
}

void BootConfig::__parsePost(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
if (!index && total > MAX_POST_SIZE) {
Interface::get().getLogger() << "Request is to large to be processed." << endl;
} else if (!index && total <= MAX_POST_SIZE) {
char* buff = new char[total + 1];
strcpy(buff, (const char*)data);
request->_tempObject = buff;
} else if (total <= MAX_POST_SIZE) {
char* buff = reinterpret_cast<char*>(request->_tempObject);
strcat(buff, (const char*)data);
if (total > MAX_POST_SIZE) {
Interface::get().getLogger() << F("Request is to large to be processed.") << endl;
} else {
if (index == 0) {
request->_tempObject = new char[total + 1];
}
void* buff = request->_tempObject + index;
memcpy(buff, data, len);
if (index + len == total) {
void* buff = request->_tempObject + total;
*(char*)buff = 0;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Homie/Boot/BootConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <ESPAsyncWebServer.h>
#include <DNSServer.h>
#include <ArduinoJson.h>

#include "../../HomieFirmwareConfig.hpp"
#include "Boot.hpp"
#include "../Constants.hpp"
#include "../Limits.hpp"
Expand Down
2 changes: 2 additions & 0 deletions src/Homie/Boot/BootNormal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <AsyncMqttClient.h>

#include "../../HomieFirmwareConfig.hpp"
#include "../../HomieNode.hpp"
#include "../../HomieRange.hpp"
#include "../../StreamingOperator.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/Homie/Boot/BootStandalone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Arduino.h"

#include "../../HomieFirmwareConfig.hpp"
#include "Boot.hpp"
#include "../../StreamingOperator.hpp"
#include "../Utils/ResetHandler.hpp"
Expand Down
6 changes: 1 addition & 5 deletions src/HomieFirmwareConfig.h → src/HomieFirmwareConfig.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@

#ifndef LIBRARIES_HOMIE_CONFIG_H
#define LIBRARIES_HOMIE_CONFIG_H
#pragma once

#ifndef HOMIE_FIRMWARE_HOMIE_BUTTON
#define HOMIE_FIRMWARE_HOMIE_BUTTON 1
#endif

#endif //

0 comments on commit 57ecb0d

Please sign in to comment.