-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfff68f
commit ed83782
Showing
10 changed files
with
211 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
"maintainer": true | ||
} | ||
], | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"frameworks": "arduino", | ||
"platforms": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=uFire SHT20 | ||
version=1.0.0 | ||
version=1.0.2 | ||
author=uFire | ||
maintainer[email protected] | ||
sentence=Measure atmospheric temperature and humdity. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#if __has_include("ArduinoJson.h") | ||
#include "uFire_SHT20_JSON.h" | ||
#include <ArduinoJson.h> | ||
|
||
void uFire_SHT20_JSON::begin(uFire_SHT20 *p_sht20) | ||
{ | ||
sht20 = p_sht20; | ||
} | ||
|
||
String uFire_SHT20_JSON::processJSON(String json) | ||
{ | ||
String cmd = json.substring(0, json.indexOf(" ", 0)); | ||
cmd.trim(); | ||
json.remove(0, json.indexOf(" ", 0)); | ||
json.trim(); | ||
String parameter = json.substring(0, json.indexOf(" ", 0)); | ||
parameter.trim(); | ||
|
||
String value = ""; | ||
if (cmd == "at") value = air_temp(); | ||
if (cmd == "ah") value = air_humidity(); | ||
if (cmd == "ac") value = air_connected(); | ||
|
||
if (value != "") | ||
{ | ||
this->value = value.toFloat(); | ||
return value; | ||
} else | ||
{ | ||
this->value = -1; | ||
return ""; | ||
} | ||
} | ||
|
||
String uFire_SHT20_JSON::air_temp() | ||
{ | ||
String output; | ||
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 20; | ||
DynamicJsonDocument doc(bufferSize); | ||
doc["at"] = sht20->temperature(); | ||
serializeJson(doc, output); | ||
return output; | ||
} | ||
|
||
String uFire_SHT20_JSON::air_humidity() | ||
{ | ||
String output; | ||
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 20; | ||
DynamicJsonDocument doc(bufferSize); | ||
doc["ah"] = sht20->humidity(); | ||
serializeJson(doc, output); | ||
return output; | ||
} | ||
|
||
String uFire_SHT20_JSON::air_connected() | ||
{ | ||
String output; | ||
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 20; | ||
DynamicJsonDocument doc(bufferSize); | ||
doc["ac"] = sht20->connected(); | ||
serializeJson(doc, output); | ||
return output; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <uFire_SHT20.h> | ||
|
||
class uFire_SHT20_JSON | ||
{ | ||
public: | ||
float value; | ||
uFire_SHT20_JSON(){} | ||
void begin(uFire_SHT20 *sht20); | ||
String processJSON(String json); | ||
private: | ||
uFire_SHT20 *sht20; | ||
String air_temp(); | ||
String air_humidity(); | ||
String air_connected(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#if __has_include("ArduinoJson.h") | ||
#include "uFire_SHT20_MP.h" | ||
#include <ArduinoJson.h> | ||
|
||
void uFire_SHT20_MP::begin(uFire_SHT20 *p_sht20) | ||
{ | ||
sht20 = p_sht20; | ||
} | ||
|
||
String uFire_SHT20_MP::processMsgPack(String json) | ||
{ | ||
String cmd = json.substring(0, json.indexOf(" ", 0)); | ||
cmd.trim(); | ||
json.remove(0, json.indexOf(" ", 0)); | ||
json.trim(); | ||
String parameter = json.substring(0, json.indexOf(" ", 0)); | ||
parameter.trim(); | ||
|
||
String value = ""; | ||
if (cmd == "at") value = air_temp(); | ||
if (cmd == "ah") value = air_humidity(); | ||
if (cmd == "ac") value = air_connected(); | ||
|
||
if (value != "") | ||
{ | ||
this->value = value.toFloat(); | ||
return value; | ||
} else | ||
{ | ||
this->value = -1; | ||
return ""; | ||
} | ||
} | ||
|
||
String uFire_SHT20_MP::air_temp() | ||
{ | ||
String output; | ||
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 20; | ||
DynamicJsonDocument doc(bufferSize); | ||
doc["at"] = sht20->temperature(); | ||
serializeMsgPack(doc, output); | ||
return output; | ||
} | ||
|
||
String uFire_SHT20_MP::air_humidity() | ||
{ | ||
String output; | ||
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 20; | ||
DynamicJsonDocument doc(bufferSize); | ||
doc["ah"] = sht20->humidity(); | ||
serializeMsgPack(doc, output); | ||
return output; | ||
} | ||
|
||
String uFire_SHT20_MP::air_connected() | ||
{ | ||
String output; | ||
const size_t bufferSize = JSON_OBJECT_SIZE(1) + 20; | ||
DynamicJsonDocument doc(bufferSize); | ||
doc["ac"] = sht20->connected(); | ||
serializeMsgPack(doc, output); | ||
return output; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <uFire_SHT20.h> | ||
|
||
class uFire_SHT20_MP | ||
{ | ||
public: | ||
float value; | ||
uFire_SHT20_MP(){} | ||
void begin(uFire_SHT20 *sht20); | ||
String processMsgPack(String json); | ||
private: | ||
uFire_SHT20 *sht20; | ||
String air_temp(); | ||
String air_humidity(); | ||
String air_connected(); | ||
}; |