MySensors plugin : Cannot send command - communications error


  • Contest Winner

    It has happened three times now, always when I am away 😞 and it usually takes about 7 days to happen:

    Screen Shot 2014-12-29 at 10.08.37 AM.png

    I know it says v1.4, but that is some kind of glitch, it was compiled and uploaded with v1.4.1.

    Anyone else have this issue?

    Wiznet Shield with Uno.

    Restarting (power-cycling) the gateway reconnects the gateway...


  • Hero Member

    @BulldogLowell I believe the Plugin Version "1.4" is correctly identified. Is there any indication what the Lua Failure is? Is it related to a com failure with the Wiznet Shield?

    I use Serial, so I'm not familiar on how to debug the Wiznet shield hardware.


  • Contest Winner

    @ServiceXp

    yeah, just like the title of the post:

    Screen Shot 2014-12-29 at 11.03.28 AM.png

    I can ping it, however.


  • Hero Member

    @BulldogLowell Happend to me recently too, but was a lot longer than 7 days of operation before it happened. Rebooted the gateway and reloaded vera to correct it. Seems like it would be very difficult to track down the cause since it happens so infrequently but the fact that it happens at all is disconcerting.


  • Contest Winner

    @Dan-S. I'm thinking it may be power related. The Ethernet shield is a power glutton and the RF takes its share. I'm using a 5V standard USB cable to power but that may drop off too much if both the radio and the ethernet shield are drawing power.

    I'm going to try scoping it with the existing power supply and then try bumping up the power or adding some capacitors to the ethernet shield's power. I tried earlier to power it with 12Volt (1200mA) power supply but the boards just got too damned hot. (that contributes to my worry that the chinese boards i have been buying are really powered correctly).

    I think a 9V power supply may improve the situation... When I'm home I'll post the traces with a few power options. We really should have a definitive reference guide to building and powering these gateways and sensors. It may be difficult though, due to the possible number of varieties available for purchase.

    One thing I really want to focus on for the MySensors extension is reliability. Version 1.4.1 seems to solve the radio problems for me, but I would like to solve my intermittent gateway issues. It doesn't seem to be in software, since so many others don't complain about losing the connection to their ethernet gateway.

    Since so many folks suffer from power issues... this may be a fun thing to focus on so that many can benefit.


  • Hero Member

    I agree that it is likely a power issue. I am using a 9v regulated power supply for the UNO/Ethernet board combo and a separate standard 5v smartphone power supply (regulated to 3.3v by an AMS117) to power the radio to try to eliminate any power issues. Maybe that's why my setup lasts longer between failures.



  • @BulldogLowell
    I experienced a similar problem a few months ago. The problem is that the MySensors-plugin sets the failure flag (luup.set_failure(true)) and the only way to reset this is to restart/reload Vera. It should be possible and rather simple to implement a reset button in the plugin to restart only the plugin.
    But I wanted the plugin to try to restart by itself and created a keep-alive function to test communication and if that fails even to try to reset the communication. This is done by trying to reopen the connection to the gateway, which only can be done by the plugin.

    I copied and pasted a little from the lua-file and found some other stuff about keep alive-functions/timers on the internet.

    I changed the L_Arduino.lua in the following way:

    Add these lines of code to the end of the startup function just before 'end':

    luup.log('start call_timer keepAlive')
    _G["keepAlive"] = keepAlive
    luup.call_timer("keepAlive", 1, "30m", "", "SomeStuff")
    

    This will start a timer which after 30 minutes ("30m") calls the function keepAlive.

    Now add the following new function just above the startup function:

    function keepAlive(stuff)
        luup.log('keepAlive!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
        sendCommandWithMessageType("0;0","INTERNAL",0,tonumber(tInternalTypes["VERSION"][1]),"Get Version")
      _G["keepAlive"] = keepAlive
        luup.call_timer("keepAlive", 1, "30m", "", "SomeStuff")
    end
    

    This will ask the gateway for the Lib version, only for the reason of testing communication. In the end you have to setup the call_timer again to keep it going.

    Now I changed the function sendCommandWithMessageType so that it looks like this:

    function sendCommandWithMessageType(altid, messageType, ack, variableId, value)
        local cmd = altid..";".. msgType[messageType] .. ";" .. ack .. ";" .. variableId .. ";" .. value
       log("Sending: " .. cmd)
    
        if (luup.io.write(cmd) == false)  then
        	-- Try to reopen the connection
        	luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable5","FEL",18)
    	    openConnectionToGateway()
    	    -- Try to resend commando
    	    if (luup.io.write(cmd) == false)  then
    		    task("Cannot send command - communications error", TASK_ERROR)
    		    luup.set_failure(true)
    		    return false
    	    end	
    	    luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable5","OK",18)
       end
       return true
    end
    

    This function now tries to reopen the connection to the gateway when the plugin can't send a command to the gateway. If even this doesn't work it sets the failure flag as before. NOTICE that I use "Variable5" in my VariableContainer with ID #18. Remove these lines or adjust them to your situation!!

    Last thing you have to do is to add the function openConnectionToGateway which you can put right before sendCommandWithMessageType:

    function openConnectionToGateway()
        log("openConnectionToGateway()")
    
        -- Set the last update in a human readable form for display on the console
        local timestamp = os.time()
        local variable = tVeraTypes["LAST_UPDATE"]
        local unit = luup.variable_get(ARDUINO_SID, "Unit", ARDUINO_DEVICE)
        local timeFormat = (unit == 'M' and '%H:%M' or '%I:%M %p')			
        luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable4",os.date(timeFormat, timestamp),18)
        -- End
    
       local ipa = luup.devices[ARDUINO_DEVICE].ip
    
        local ipAddress = string.match(ipa, '^(%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?)')
        local ipPort    = string.match(ipa, ':(%d+)$')
    
        if (ipAddress ~= nil) then
           if (ipPort == nil) then ipPort = IP_PORT end
    
           log('Using network connection: IP address is '..ipAddress..':'..ipPort)
           luup.io.open(ARDUINO_DEVICE, ipAddress, ipPort)
        end
    end
    

    This function takes care of reopening the connection to the gateway. NOTICE that I use "Variable4" of my VariableContainer with ID #18 to show the moment this function was called. Remove this code or adjust it to your situation!!

    Don't know if this it what you want but it works perfectly for me! Never had to reload Vera because of the gateway loosing connection for a short moment of time!

    Good luck!

    Magnus


  • Contest Winner

    @MagKas thanks Magnus, I'll have to take a look at this when I'm back.

    A vera restart does not correct my communication issue, so adding the openConnectionToGateway function will allow it to reconnect? If that works for me, it is a terrific solution!

    I may come back to you on this, I've learned lua, but the extensions for vera, not so much.

    I appreciate your assistance...

    Jim



  • @BulldogLowell
    Oh, I'm sorry! I missed the line where you wrote that you have to restart the gateway to get it to work again. In my case it was sufficient to reload Vera. So my solution probably won't help you...

    Very strange though that you are able to ping the gateway but that there is no communication with the plugin. What happens when you reload Vera? Do you get the error-message immediatly or after some longer time?

    The only place in the lua-code of the plugin where this error message is set is in the function sendCommandWithMessageType when luup.io.write(cmd) is failing.
    In theory this should be solved by reloading Vera, unless your communication is still failing.
    You might want to examine (read: Google) what could be the cause of luup.io.write() to fail.


  • Contest Winner

    @MagKas

    when I reload vera, it takes some time to come back with the error message.

    [EDIT] it takes one minute from "loading startup lua" until error...

    I cannot understand why it will return a ping and yet it doesn't connect.

    I'll search with your advice...

    thanks



  • I had several times the same problem.

    Check the IP configuration in the mysensors plugin, the IP adress change for no reason, i have to investigate this.


  • Contest Winner

    @cheesepower

    @cheesepower said:

    I had several times the same problem.

    Check the IP configuration in the mysensors plugin, the IP adress change for no reason, i have to investigate this.

    Thanks. I checked but the ip I'm using matches ok....

    So far, only a hard reset of the arduino and a vera restart seem to reconnect the two.

    I'm going to try a ping up the power supply.



  • I have same error when I am trying to get EthernetGateway (Nano+NRF24L01+w5100) to work with Vera3.

    The gateway answers to ping in my LAN ip 192.168.100.222
    And seems to be working well and receives sensor messages as seen in USB serial:
    0;0;3;0;14;Gateway startup complete.
    0;0;3;0;9;read: 1-1-0 s=4,c=1,t=2,pt=2,l=2:0
    1;4;1;0;2;0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=0,pt=7,l=5:42.3
    1;2;1;0;0;42.3
    0;0;3;0;9;read: 1-1-0 s=3,c=1,t=2,pt=2,l=2:1
    1;3;1;0;2;1
    ...

    But the vera plugin fails to getVersion:

    50 01/11/15 21:30:05.658 luup_log:80: Arduino plugin: loading library L_Arduino ... <0x2bf45680>
    50 01/11/15 21:30:05.687 luup_log:80: Arduino plugin: library L_Arduino loaded LEAK this:163840 start:741376 to 0x10e9000 <0x2bf45680>
    50 01/11/15 21:30:05.687 luup_log:80: Arduino: urn:upnp-arduino-cc:serviceId:arduino1,PluginVersion, 1.4, 80 <0x2bf45680>
    50 01/11/15 21:30:05.688 luup_log:80: Arduino: Using network connection: IP address is 192.168.100.222:5003 <0x2bf45680>
    50 01/11/15 21:30:35.040 luup_log:80: Arduino: Sending: 0;0;3;0;2;Get Version <0x2bf45680>
    02 01/11/15 21:31:05.084 luup_log:80: Arduino: Cannot send command - communications error <0x2bf45680>

    Restarting luup, reloading UI6 or rebooting vera3 does not help.

    Any ideas? I'm stuck so please help.



  • Just to add that I am using 1.4.1 library and SOFTSPI was defined when compiling the EthernetGateway. And since the EthernetGateway responds to ping and receives sensor values I assumes it is working properly.

    Is there another way to confirm the proper operation e.g. with telnet to the port 5003 or how to issue similar simulated request that Vera does when calling getVersion?

    I'm out of home automation before this is solved! 😞


  • Admin

    I checked in a small update yesterday which changes order of initialization between radio/ethernet. This has helped a few on the forum lately. I have no idea if this is related to your problem though.



  • @hek said:

    I checked in a small update yesterday which changes order of initialization between radio/ethernet. This has helped a few on the forum lately. I have no idea if this is related to your problem though.

    Thanks, but I did that too and it helped to resurrect it since before it did not respond to ping.
    Now it does so I think it works, but could it still be something in the node?

    In the EthernetGateway wiring instructions it says to connect:
    13 SCK
    12 MISO/SO
    11 MOSI/SI
    10 SS/CS

    But in the RF24_config.h it reads:
    const uint8_t SOFT_SPI_MISO_PIN = 16;
    const uint8_t SOFT_SPI_MOSI_PIN = 15;
    const uint8_t SOFT_SPI_SCK_PIN = 14;

    So how should it be? Should I change the RF24_config.h or the wiring?

    And by the way the W5100 has label for +5V and not 3.3V as the wiring instructions..


  • Admin

    Follow this:
    http://www.mysensors.org/build/ethernet_gateway

    A0 = 14
    A1 = 15
    ...



  • @hek said:

    Follow this:
    http://www.mysensors.org/build/ethernet_gateway

    A0 = 14
    A1 = 15
    ...

    Ok the wirings were otherwise correct since it started working once I fed +5V instead of 3.3V to the W5100.
    So I am back online with the home automation.. Phew..



  • ok great thread as I want to also change to an Ethernet gw
    But here is the rookie question, after there has been a ping to the gw there is lots of info shown in these dissussions ie unit8 .....
    o;0;3;9 read.....
    and many others, at this time it is mostly gibberish to me but have looked at the mysensors ver 1.4
    I just want to understand and learn what you guys are posting and why.
    One silly last question is I am using lib 1.4 is the github download now lib 1.4.1? and do I need to upgrade?
    Yes this old dog is still learning!, it is a blast the people are very helpful.



  • @5546dug
    Yes I think you need 1.4.1 or latest. The messages you see (0;0;3;9...) are traffic in the wireless sensor network.

    My problem appeared again. The EthernetGateway responds to Ping but Vera plugin says:
    "Cannot send command - communications error"

    So perhaps increasing power could help, but how? Is adding capacitors enough?? Like for the radio there already is one..


Log in to reply
 

Suggested Topics

  • 6
  • 2
  • 5
  • 20
  • 6
  • 9

49
Online

11.4k
Users

11.1k
Topics

112.6k
Posts