Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

VD error - not found t_end at character 1


Question

My Virtual Device (VD) get stuck after a while trying to decode json data.

 

The error is:  

expected value but found t_end at character 1

 

Is there any solution to fix that? I've tried to add more seconds with fibaro:sleep but no results.

 

Thanks for your help,

Tomax

Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Hi! That means your json data is empty (well... not exactly, but kind of). Probably, the server or REST API which is expected to send data is offline or have a problem.

 

To avoid this error, you can do that :

Please login or register to see this code.

Or, maybe better :

Please login or register to see this code.

 

Link to post
Share on other sites
  • 0
  • Inquirer
  • Bodyart, this is the code:

    ----------------------------------------------------------------------
    local smartmeter= Net.FHttp(selfIp, 80);
    response = smartmeter:GET("/")

     

    if response~=nil 
    then (doing my stuff:)

                 if... then

                 elseif... then

                 elseif... then

                 end

    else fibaro:debug('Error json')

    end

    -------------------------------------------------------------------------

     

    I'm getting that error when VD trying to get Json data from the remote Arduino. It is not happenning all the time, but few times per day.

     

     

     

     

     

    OJC, thanks for feedback.
    I'll play around with your code then I'll let you know if it's working or not.

    Edited by Tomax
    Link to post
    Share on other sites
    • 0
  • Inquirer
  • OJC, here is the test:

     

    1. I've insterted the code (value "volt" is sent by the server via json):

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    local isOk, volt = pcall(function() return json.decode(response) end)
    if not (isOk) then
      fibaro:debug('[ERROR] Invalid JSON:' .. tostring(response))
      fibaro:sleep(60000)
    else
      fibaro:debug('Great!  "Volt" value is confirmed in the transferred JSON')
    end

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

     

    2.  I've manually stop the server (JSON sender). Ok, the error was succesfully trapped... so the script reported correctly: [ERROR] Invalid JSON:' .. tostring(response)

    3. Then I've start the server (JSON sender). But I've got again the mainly error of the stucked VD: not found t_end at character 1

     

     

    Edited by Tomax
    Link to post
    Share on other sites
    • 0
  • Inquirer
  • Hi again, OJC

     

    Since with your help at least I was able to catch the error (an very important step) before falling in the T_END error which completely blocked the rest of the code,

    I moved on and now I'm testing this improved code:

     

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    local isOk, volt = pcall(function() return json.decode(response) end)
    while (isOk == false) do
      fibaro:debug('[ERROR] Invalid JSON:' .. tostring(response))
      fibaro:sleep(60000) --here I'm waiting a little bit since Arduino is not such a fast server... my Arduino is dealing with few other Virtual Devices and maybe is getting tired :) 
    end

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

     

    I'll be back if no success. 

    Link to post
    Share on other sites
    • 0
    4 hours ago, Tomax said:

    fibaro:sleep(60000) --here I'm waiting a little bit since Arduino is not such a fast server... my Arduino is dealing with few other Virtual Devices and maybe is getting tired :)

    Just thinking out loud... Maybe it is not the speed of your device, but the fact it can handle only one connection at a time? That would depend on the exact device, the library in use and how you wrote that code. I think, for instance, this applies to ESP8266, but I have not tested it extensively. Also, maybe you get a communication error from time to time (it is wifi?) and then the "Arduino" might only release that single connection after it has timed out... and your HC has timed out. But OK, 60 seconds of sleep seems reasonable to work around the problem.

    Link to post
    Share on other sites
    • 0
  • Inquirer
  • Hi Peter, I was thinking that maybe it is a known Fibaro issue. But since not many people got trapped into, I'll have  to play around the Arduino board and script. 

    Today I've upgraded the old sender (Arduino Uno) with a new one (Arduino Mega). If that more power will not be sufficient, then I'll try to optimise the code there.  

    if any ideea come up meanwhile, let me have it, please! Thanks!

     

     

     

     

    OJC, the last version of code (while do) it doesn't solve the problem. I'm trapped into a continue loop.

    Edited by Tomax
    Link to post
    Share on other sites
    • 0
    20 hours ago, Tomax said:

    Hi Peter, I was thinking that maybe it is a known Fibaro issue.

     

    Oh, yes, actually it is, but it is very rare... You could argue this is a bug, because you probably did not expect your VD to crash because of a JSON decode failure... I highly recommend "pcall" as soon as you communicate "with the outside world" and use delays to retry (like ... try again in 5 minutes).

     

    20 hours ago, Tomax said:

    OJC, the last version of code (while do) it doesn't solve the problem. I'm trapped into a continue loop.

    You might have to restart communication with your device, not only the decode, because it is probably not the JSON library that fails... it has got invalid data.

     

    You have this in your code, what does it print when it happens?

     

    fibaro:debug('[ERROR] Invalid JSON:' .. tostring(response))

     

     

     

     

    Link to post
    Share on other sites
    • 0
  • Inquirer
  • T_END bug/error seems to be fixed now. My final tested code is:

    ===================================================

    --start sync Arduino
    local smartmeter = Net.FHttp(selfIp, 80);
    response = smartmeter:GET("/")
    local isOk = pcall(function() return json.decode(response) end)

     

    --here is starting the loop

    while response == smartmeter:GET("/") and isOk == false 
    do 
      fibaro:debug('Lost signal from Arduino!') -- .. tostring(response))
      fibaro:sleep(2000)
    end


    -- Refresh / Check AGAIN the respose from Arduino. This is important since here is came the refreshed data to be used later on!!!
        response = smartmeter:GET("/")
    -- And process the response. Bellow add your code to do whatever you want.

    ===================================================

     

     

    Link to post
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...