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 :slight_smile:

Maybe lose the newline?

It's an iterator; the variable val takes the value of each of the elements of the array values in turn.

@prutz, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

@sterretje Thanks for moving it to the right location! :slight_smile:


Well I would like to display the vallues on the LCD. How could I extract/parse the values to an interger? So I can for example do this: (Compiling gives an error)

int WN_Watt: KEY_POWER; 

        lcd.setCursor(0, 0);                      // Print to first row of LCD
        lcd.printf("Watts: %d\n", WN_Watt);       // Watts producing at the moment
        lcd.setCursor(0, 1);                      // Print to second row of LCD
        lcd.printf("Day yield: %d\n", DY_Watt)    // Day yield in Watts/h

I wouldn't ever use a newline on an LCD, unless I knew the driver supported it

It looks to me like yours doesn't.

Not sure what that is
Did you mean '::' ?

This is the LCD I'm using: Grove - 16x2 LCD - Seeed Wiki
And the driver I've installed: GitHub - Seeed-Studio/Grove_LCD_RGB_Backlight: Seeedstudio, Grove - LCD RGB Backlight

I would like to get the int values out of KEY_POWER and KEY_ENERGY_TODAY keys.
For example:
When the solar has produced 1688 W/h this value (1688) will be stored under KEY_ENERGY_TODAY.
The KEY_ENERGY_TODAY value that to be copied to the new int called 'DY_Watt'. And the same for KEY_POWER to 'WN_Watt'.

I do somehow get that 'val' copies the 'values' but still is a mystery how to get the values out separate. :slight_smile:


ooh sorry! now I get what you mean with newline. Getting rid of '/n'. :slight_smile:

edit no.2

Removing /n did the job by removing the strange character.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.