Skip to content

Commit

Permalink
Merge pull request #8 from Caffreyfans/dev
Browse files Browse the repository at this point in the history
Fix save config error
  • Loading branch information
Caffreyfans authored Aug 18, 2020
2 parents 8fdc9bf + d92c024 commit f6ed8a9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
49 changes: 21 additions & 28 deletions src/IRbaby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "IRbabyUserSettings.h"
#include "IRbabyRF.h"

void registerDevice(); // device info upload to devicehive
void uploadIP(); // device info upload to devicehive
void ICACHE_RAM_ATTR resetHandle(); // interrupt handle
Ticker mqtt_check; // MQTT check timer
Ticker disable_ir; // disable IR receive
Expand All @@ -47,15 +47,17 @@ void setup()
pinMode(RESET_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(RESET_PIN), resetHandle, ONLOW);
INFOLN();
INFOLN(
" ___________ _ _ \n"
"|_ _| ___ \\ | | | \n"
" | | | |_/ / |__ __ _| |__ _ _ \n"
" | | | /| '_ \\ / _` | '_ \\| | | |\n"
" _| |_| |\\ \\| |_) | (_| | |_) | |_| |\n"
" \\___/\\_| \\_|_.__/ \\__,_|_.__/ \\__, |\n"
" __/ |\n"
" |___/ \n");
INFOLN("8888888 8888888b. 888 888 ");
INFOLN(" 888 888 Y88b 888 888 ");
INFOLN(" 888 888 888 888 888 ");
INFOLN(" 888 888 d88P 88888b. 8888b. 88888b. 888 888 ");
INFOLN(" 888 8888888P 888 88b 88b 888 88b 888 888 ");
INFOLN(" 888 888 T88b 888 888 .d888888 888 888 888 888 ");
INFOLN(" 888 888 T88b 888 d88P 888 888 888 d88P Y88b 888 ");
INFOLN("8888888 888 T88b 88888P Y888888 88888P Y88888 ");
INFOLN(" Y8b d88P ");
INFOLN(" Y88P ");

wifi_manager.autoConnect();

settingsLoad(); // load user settings form fs
Expand All @@ -67,7 +69,7 @@ void setup()
#endif
loadIRPin(ConfigData["pin"]["ir_send"], ConfigData["pin"]["ir_receive"]);; // IR init
#ifdef USE_INFO_UPLOAD
registerDevice();
uploadIP();
#endif
mqtt_check.attach_scheduled(MQTT_CHECK_INTERVALS, mqttCheck);
disable_ir.attach_scheduled(DISABLE_SIGNAL_INTERVALS, disableIR);
Expand Down Expand Up @@ -110,31 +112,22 @@ void resetHandle()
settingsClear();
}

void registerDevice()
// only upload chip id
void uploadIP()
{
HTTPClient http;
String head = "http://api.ipify.org/?format=json";
http.begin(wifi_client, head);
http.GET();
String ip = http.getString();
StaticJsonDocument<128> ip_json;
deserializeJson(ip_json, ip);
JsonObject ip_obj = ip_json.as<JsonObject>();
http.end();
HTTPClient http2;
StaticJsonDocument<128> body_json;
String chip_id = String(ESP.getChipId(), HEX);
chip_id.toUpperCase();
head = "http://playground.devicehive.com/api/rest/device/";
String head = "http://playground.devicehive.com/api/rest/device/";
head += chip_id;
http2.begin(wifi_client, head);
http2.addHeader("Content-Type", "application/json");
http2.addHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiJ9.eyJwYXlsb2FkIjp7ImEiOlsyLDMsNCw1LDYsNyw4LDksMTAsMTEsMTIsMTUsMTYsMTddLCJlIjoxNzQzNDM2ODAwMDAwLCJ0IjoxLCJ1Ijo2NjM1LCJuIjpbIjY1NDIiXSwiZHQiOlsiKiJdfX0.WyyxNr2OD5pvBSxMq84NZh6TkNnFZe_PXenkrUkRSiw");
http.begin(wifi_client, head);
http.addHeader("Content-Type", "application/json");
http.addHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiJ9.eyJwYXlsb2FkIjp7ImEiOlsyLDMsNCw1LDYsNyw4LDksMTAsMTEsMTIsMTUsMTYsMTddLCJlIjoxNzQzNDM2ODAwMDAwLCJ0IjoxLCJ1Ijo2NjM1LCJuIjpbIjY1NDIiXSwiZHQiOlsiKiJdfX0.WyyxNr2OD5pvBSxMq84NZh6TkNnFZe_PXenkrUkRSiw");
body_json["name"] = chip_id;
body_json["networkId"] = "6542";
body_json["data"] = ip_obj;
String body = body_json.as<String>();
INFOF("update %s to devicehive\n", body.c_str());
http2.PUT(body);
http2.end();
http.PUT(body);
http.end();
}
2 changes: 1 addition & 1 deletion src/IRbabyIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void loadIRPin(uint8_t send_pin, uint8_t recv_pin)
delete ir_recv;
}
ir_send = new IRsend(send_pin);
DEBUGF("load send pin at %d\n", send_pin);
DEBUGF("Load IR send pin at %d\n", send_pin);
ir_send->begin();
ir_recv = new IRrecv(recv_pin, kCaptureBufferSize, kTimeout, true);
disableIR();
Expand Down
6 changes: 3 additions & 3 deletions src/IRbabyMsgHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool msgHandle(StaticJsonDocument<1024> *p_recv_msg_doc, MsgType msg_type)
LittleFS.info(fsinfo);
String fs_total_bytes = String(fsinfo.totalBytes / 1024) + "KB";
String fs_used_bytes = String(fsinfo.usedBytes / 1024) + "KB";
send_msg_doc["cmd"] = "info_rt";
send_msg_doc["cmd"] = "query_info";
send_msg_doc["params"]["free_mem"] = free_mem;
send_msg_doc["params"]["chip_id"] = chip_id;
send_msg_doc["params"]["cpu_freq"] = cpu_freq;
Expand Down Expand Up @@ -251,8 +251,8 @@ bool msgHandle(StaticJsonDocument<1024> *p_recv_msg_doc, MsgType msg_type)
if (params.containsKey("mqtt")) {
ConfigData["mqtt"]["host"] = params["mqtt"]["host"];
ConfigData["mqtt"]["port"] = params["mqtt"]["port"];
ConfigData["mqtt"]["user"] = params["mqtt"]["host"];
ConfigData["mqtt"]["password"] = params["mqtt"]["host"];
ConfigData["mqtt"]["user"] = params["mqtt"]["user"];
ConfigData["mqtt"]["password"] = params["mqtt"]["password"];
}
if (params.containsKey("pin")) {
ConfigData["pin"]["ir_send"] = params["pin"]["ir_send"];
Expand Down
8 changes: 4 additions & 4 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ typedef unsigned short uint16_t;
typedef short int16_t;
typedef unsigned char uint8_t;

#define FIRMWARE_VERSION "v0.6" // version name
#define VERSION_CODE 6 // version code
#define FIRMWARE_VERSION "v0.7" // version name
#define VERSION_CODE 7 // version code

/* log settings */
#define BAUD_RATE 115200
Expand All @@ -28,7 +28,7 @@ typedef unsigned char uint8_t;

/* ----------------- user settings ----------------- */
/* mqtt settings */
#define MQTT_CHECK_INTERVALS 10 // seconds
#define MQTT_CHECK_INTERVALS 15 // seconds
#define MQTT_CONNECT_WAIT_TIME 20000 // MQTT 连接等待时间

/* receive disable */
Expand All @@ -37,7 +37,7 @@ typedef unsigned char uint8_t;
// uncomment below to enable RF
// #define USE_RF

// uncomment below to enable upload board info to remote server
// uncomment below to enable upload chip id to remote server
// #define USE_INFO_UPLOAD

/* ----------------- default pin setting --------------- */
Expand Down

0 comments on commit f6ed8a9

Please sign in to comment.