This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Api Error
#1
Hello
I am trying to read this data with the Api provided by the manufacturer and I am having problems as it gives me the following error.
when I try to read item "1"
    Error de sintaxis en la linea 28: ')' expected near '.1' 
Assistant screenshot

The first thing I have to do is comment on the following variables because otherwise I can't read anything
Assistant screenshot

--potencia = data.PAC.Values
--total = data.TOTAL_ENERGY

so that at least read the variable "day"
and point only to the "Values" element so that it returns the 2 values in the "log"
Where is the error, how could I read all the values of the elements?

Thank you



API

{
  "Body":{
      "Data":{
        "DAY_ENERGY":{
            "Unit":"Wh",
            "Values":{
              "1":56350,
              "2":85580
            }
        },
        "PAC":{
            "Unit":"W",
            "Values":{
              "1":7018,
              "2":10434
            }
        },
        "TOTAL_ENERGY":{
            "Unit":"Wh",
            "Values":{
              "1":7979740,
              "2":6941850
            }
        },
        "YEAR_ENERGY":{
            "Unit":"Wh",
            "Values":{
              "1":4525021,
              "2":6941852
            }
        }
      }
  },
  "Head":{
      "RequestArguments":{
        "DeviceClass":"Inverter",
        "Scope":"System"
      },
      "Status":{
        "Code":0,
        "Reason":"",
        "UserMessage":""
      },
      "Timestamp":"2020-05-20T16:45:38+02:00"
  }
}
Reply
#2
Post your script and what do you get when you log data?
------------------------------
Ctrl+F5
Reply
#3
Hi,

Are you trying to read this JSON direct (not possible to do, so your error might come from there) or do you have json.pdecode somewhere to convert it to a LUA table? 

What i see in first sight is your table has other fields, first of all Data is with a capital D so the fields should be tablename.Data.PAC.Values but i also see a main wrapping table called Body so shouldn’t your code be tablename.Body.Data.PAC.Values ?

BR,

Erwin
Reply
#4
(20.05.2020, 18:00)Erwin van der Zwart Wrote: Hi,

Are you trying to read this JSON direct (not possible to do, so your error might come from there) or do you have json.pdecode somewhere to convert it to a LUA table? 

What i see in first sight is your table has other fields, first of all Data is with a capital D so the fields should be tablename.Data.PAC.Values but i also see a main wrapping table called Body so shouldn’t your code be tablename.Body.Data.PAC.Values ?

BR,

Erwin
Hi Erwin
I have a json.decode somewhere to convert it to a LUA table

effectively the problem was capital D but when I try to read the Value of field 1 with the following command

Line 21    day = data.Body.Data.DAY_ENERGY.Values.1


"Body":{
      "Data":{
        "DAY_ENERGY":{
            "Unit":"Wh",
            "Values":{
              "1":56350,
              "2":85580

it gives me a syntax error

Error de sintaxis en la linea 21: ')' expected near '.1'


If I execute the sentence as follows

Line 21      day = data.Body.Data.DAY_ENERGY.Values

I open the registration window I see the 2 values perfectly


How can I read the value 1 and 2 from the table?


I do not know how to send a screenshot to send the script because when I give the insert image icon it asks me for a URL or how to send a screenshot

Thank you
Reply
#5
You can paste it as text or use attachment to add image. Log data and paste the result here
------------------------------
Ctrl+F5
Reply
#6
Hi,

Try: data.Body.Data.DAY_ENERGY.Values[1] or data.Body.Data.DAY_ENERGY.Values['1']

BR,

Erwin
Reply
#7
(21.05.2020, 19:24)Erwin van der Zwart Wrote: Hi,

Try: data.Body.Data.DAY_ENERGY.Values[1] or data.Body.Data.DAY_ENERGY.Values['1']

BR,

Erwin

Thank you very much that was the mistake
it's ready   Wink
Reply


Forum Jump: