Skip to content

Commit

Permalink
Update main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
merschie committed Jun 28, 2023
1 parent 472c29b commit 7fa967e
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>
#include <Adafruit_NeoPixel.h>
#define PINPV D4
#define PINBAT D3
#define PINPV D3
#define PINBAT D4
#define LEDS 19

const char ssid[] = WIFI_SSID;
const char password[] = WIFI_PASSWD;
WiFiClient wifiClient;
Adafruit_NeoPixel PVstrip = Adafruit_NeoPixel(19, PINPV, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel Batstrip = Adafruit_NeoPixel(19, PINBAT, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel PVstrip = Adafruit_NeoPixel(LEDS, PINPV, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel Batstrip = Adafruit_NeoPixel(LEDS, PINBAT, NEO_GRB + NEO_KHZ800);
int numLed = 0;
int LastLedBrightness = 0;
int numConsumptionLED = 0;
Expand All @@ -37,12 +38,17 @@ void setup() {

PVstrip.begin();
PVstrip.setBrightness(50);
Batstrip.begin();
Batstrip.setBrightness(50);


//clear strip
for (int i = 0; i < 19; i++){
PVstrip.setPixelColor(i, PVstrip.Color(0, 0, 0));
Batstrip.setPixelColor(i, PVstrip.Color(0, 0, 0));
}
PVstrip.show();
Batstrip.show();
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello World!");
Expand All @@ -63,7 +69,7 @@ void loop() {

//POST request
HTTPClient http;
http.begin(wifiClient,"http://192.168.178.59/");
http.begin(wifiClient,"http://espressif/");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST("optType=ReadRealTimeData&pwd=SRCMLTKJL9");
String payload = http.getString();
Expand All @@ -76,9 +82,15 @@ void loop() {

http.end();
//convert payload to JSON
StaticJsonDocument<1024> doc;
StaticJsonDocument<2048> doc;
deserializeJson(doc, payload);

//print each value
/* for (int i = 0; i < doc["Data"].size(); i++){
Serial.print("\n" + String(i) + ": ");
int x = doc["Data"][i];
Serial.print(x);
} */


int pv1 = doc["Data"][14];
Expand All @@ -88,9 +100,9 @@ void loop() {
int pvTotal = pv1 + pv2;


Serial.println(pv1);
Serial.println(pv2);
Serial.println(pvTotal);
Serial.println(cons);
Serial.println(batTotal);



Expand All @@ -102,9 +114,11 @@ void loop() {
LastLedBrightness = (pvTotal % 200)*255/200;
}
else{
numLed = 5+ (pvTotal/1000);
numLed = 4+ (pvTotal/1000);
LastLedBrightness = (pvTotal % 1000)*255/1000;
}




if (cons < 1001){
Expand All @@ -113,12 +127,15 @@ void loop() {
LastConsumptionLedBrightness = (cons % 200)*255/200;
}
else{
numConsumptionLED = 5 + (cons/1000);
LastConsumptionLedBrightness = 5 + (cons % 1000)*255/1000;
numConsumptionLED = 4 + (cons/1000);
LastConsumptionLedBrightness = 4 + (cons % 1000)*255/1000;
}

Serial.println(numLed);
Serial.println(numConsumptionLED);

batLedNum = (batTotal-10) / 9;

batLedNum = ((batTotal-10) /90.0)*LEDS;
batLedBrightness = (batTotal-10) % 9 * 255/9;

for (int i = 0; i < 19; i++){
Expand Down Expand Up @@ -172,7 +189,7 @@ void loop() {
Batstrip.setPixelColor(batLedNum, Batstrip.Color(0, batLedBrightness, 0));
Batstrip.show();


Serial.println("---------------------");
//wait 10 seconds
delay(10000);

Expand Down

0 comments on commit 7fa967e

Please sign in to comment.