Hi,
For my SMA Sunnyboy Solar inverter I wanted to make a Huzzah Feather ESP8266 with a display to show first row the wattage and second row yield of the day.
I'm using this sketch: GitHub - pkoerber/SMA-SunnyBoy-Reader: Reading a SMA SunnyBoy solar inverter with an esp8266 or esp32
Did got some problems with compiling but after downgrading the ESP8266 software I got it working. Yippie!
Now I want to modify the demo sketch to suit my idea. Played around for a while to get watts and day yield to display but couldn't get it working.
Full code: SMA-SunnyBoy-Reader/SMAReader_Demo.ino at main · pkoerber/SMA-SunnyBoy-Reader · GitHub
My code which is shorten and added the include LCD :
void loop() {
// wait for WiFi connection
if(WiFi.status() == WL_CONNECTED) {
// getValues int example
String keys[2]={KEY_POWER, KEY_ENERGY_TODAY};
int values[2];
bool isSuccess=smaReader.getValues(2, keys, values);
Serial.printf("Getting values: %s\n", isSuccess?"success":"fail");
if(isSuccess) {
for(int val: values) {
Serial.printf("Value: %d\n", val);
lcd.setCursor(0, 0); // I added this
lcd.printf("Value: %d\n", val); // I added this
}
}
..........................
What I know so far:
The array keys[2]: So under keys[0] is KEY_POWER and keys [1] KEY_ENERGY_TODAY, right?
The KEY_POWER and KEY_ENERGY_TODAY consist of key numbers (6100_40263F00 and 6400_00262200). This is were the value is stored.
Serial is showing:
Value=-1 is KEY_POWER (no sun atm) in watts
Value= 1688 is KEY_POWER_TODAY in Watt/h today.
17:15:32.983 -> Getting values: success
17:15:33.030 -> Value: -1
17:15:33.030 -> Value: 1688
LCD Display now is just showing "Value: 1688 (and a weird chinese sign)".
As I don't get how the code works I find it difficult to get the LCD working properly and hoping someone could explain what exactly happens in de code.
.......................
I'll try to explain my self how to code works:
bool isSuccess=smaReader.getValues(2, keys, values);
This is the function that loads the values of the keys into the array and gives out a success or fail when it worked or not?
if(isSuccess) {
for(int val: values) {
Serial.printf("Value: %d\n", val);
If loading the values into the array was sucessfull it prints out the values to the serial.
This is where I get lost.. Even I only see one time Serial.printf in the code it does print out both key vallues.
Normally you will see an array[i]++ or i<2:i+1 or something like that. But this seems to work very different.
Also the colon in this line is confusing.
for(int val: values) {
Hope someone can give me a little push in the back