Skip to content

Commit

Permalink
Preparations for send telemetry (no ssl)
Browse files Browse the repository at this point in the history
  • Loading branch information
o0shojo0o committed Aug 21, 2022
1 parent d283295 commit b12ca08
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
6 changes: 6 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ lib_deps =
adafruit/Adafruit BMP280 Library@^2.6.1
claws/BH1750@^1.2.0
robtillaart/Max44009@^0.5.2
arduino-libraries/ArduinoHttpClient@^0.4.0
Hash = https://github.com/bbx10/Hash_tng.git

[env:ESP8266]
platform = [email protected]
Expand All @@ -65,6 +67,8 @@ lib_deps =
adafruit/Adafruit BMP280 Library@^2.6.1
claws/BH1750@^1.2.0
robtillaart/Max44009@^0.5.2
arduino-libraries/ArduinoHttpClient@^0.4.0
mr-glt/SHA-1 Hash@^1.1.0

[env:d1_mini]
platform = [email protected]
Expand All @@ -81,3 +85,5 @@ lib_deps =
adafruit/Adafruit BMP280 Library@^2.6.1
claws/BH1750@^1.2.0
robtillaart/Max44009@^0.5.2
arduino-libraries/ArduinoHttpClient@^0.4.0
mr-glt/SHA-1 Hash@^1.1.0
38 changes: 33 additions & 5 deletions src/PixelIt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include "ColorConverterLib.h"
#include <TimeLib.h>
#include <ArduinoJson.h>
#include <ArduinoHttpClient.h>
#include <Hash.h>
// PixelIT Stuff
#include "PixelItFont.h"
#include "Webinterface.h"
Expand Down Expand Up @@ -89,6 +91,9 @@ String ldrDevice = "GL5516";
unsigned long ldrPulldown = 10000; // 10k pulldown-resistor
unsigned int ldrSmoothing = 0;

String serverAddress = "pixelit.bastelbunker.de";
int serverPort = 80;

String btnPin[] = {"Pin_D0", "Pin_D4", "Pin_D5"};
bool btnEnabled[] = {false, false, false};
int btnPressedLevel[] = {LOW, LOW, LOW};
Expand Down Expand Up @@ -174,6 +179,7 @@ WiFiClient espClient;
WiFiUDP udp;
PubSubClient client(espClient);
WiFiManager wifiManager;
HttpClient httpClient = HttpClient(espClient, serverAddress, serverPort);
#if defined(ESP8266)
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;
Expand Down Expand Up @@ -276,7 +282,7 @@ float temperatureOffset = 0.0f;
float humidityOffset = 0.0f;
float pressureOffset = 0.0f;
float gasOffset = 0.0f;
bool sendStats = true;
bool sendTelemetry = true;
bool checkUpdateScreen = true;
// MP3Player Vars
String OldGetMP3PlayerInfo;
Expand Down Expand Up @@ -367,7 +373,7 @@ void SaveConfig()
json["ldrPulldown"] = ldrPulldown;
json["ldrSmoothing"] = ldrSmoothing;
json["initialVolume"] = initialVolume;
json["sendStats"] = sendStats;
json["sendTelemetry"] = sendTelemetry;
json["checkUpdateScreen"] = checkUpdateScreen;

#if defined(ESP8266)
Expand Down Expand Up @@ -702,9 +708,9 @@ void SetConfigVariables(JsonObject &json)
initialVolume = json["initialVolume"].as<uint>();
}

if (json.containsKey("sendStats"))
if (json.containsKey("sendTelemetry"))
{
sendStats = json["sendStats"].as<bool>();
sendTelemetry = json["sendTelemetry"].as<bool>();
}

if (json.containsKey("checkUpdateScreen"))
Expand Down Expand Up @@ -1716,6 +1722,21 @@ String GetButtons()
return json;
}

String GetTelemetry()
{
DynamicJsonBuffer jsonBuffer;
JsonObject &root = jsonBuffer.createObject();

root["uuid"] = sha1(GetChipID());
root["version"] = VERSION;
root["type"] = isESP8266 ? "esp8266" : "esp32";

String json;
root.printTo(json);

return json;
}

/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
void DrawText(String text, int bigFont, int colorRed, int colorGreen, int colorBlue, int posX, int posY)
Expand Down Expand Up @@ -3130,7 +3151,7 @@ void setup()
// Config menue timeout 180 seconds.
wifiManager.setConfigPortalTimeout(180);

if (!wifiManager.autoConnect("PIXEL_IT"))
if (!wifiManager.autoConnect("PIXELIT"))
{
Log(F("Setup"), F("Wifi failed to connect and hit timeout"));
delay(3000);
Expand Down Expand Up @@ -3190,6 +3211,13 @@ void setup()
mp3Player.begin(*softSerial);
Log(F("Setup"), F("DFPlayer started"));
mp3Player.volume(initialVolume);

if (sendTelemetry == true)
{
Log(F("Setup"), F("Telemetry send"));
httpClient.sendHeader("User-Agent", "PixelIt");
httpClient.post("/api/telemetry", "application/json", GetTelemetry());
}
}

void loop()
Expand Down

0 comments on commit b12ca08

Please sign in to comment.