Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. MySensors plugin : Cannot send command - communications error

MySensors plugin : Cannot send command - communications error

Scheduled Pinned Locked Moved Troubleshooting
ethernetgateway
20 Posts 8 Posters 9.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M MagKas

    @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

    BulldogLowellB Offline
    BulldogLowellB Offline
    BulldogLowell
    Contest Winner
    wrote on last edited by
    #8

    @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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MagKas
      wrote on last edited by
      #9

      @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.

      BulldogLowellB 1 Reply Last reply
      0
      • M MagKas

        @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.

        BulldogLowellB Offline
        BulldogLowellB Offline
        BulldogLowell
        Contest Winner
        wrote on last edited by BulldogLowell
        #10

        @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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cheesepower
          wrote on last edited by
          #11

          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.

          BulldogLowellB 1 Reply Last reply
          0
          • C cheesepower

            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.

            BulldogLowellB Offline
            BulldogLowellB Offline
            BulldogLowell
            Contest Winner
            wrote on last edited by
            #12

            @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.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              samppa
              wrote on last edited by samppa
              #13

              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.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                samppa
                wrote on last edited by
                #14

                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! :-(

                1 Reply Last reply
                0
                • hekH Offline
                  hekH Offline
                  hek
                  Admin
                  wrote on last edited by
                  #15

                  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.

                  S 1 Reply Last reply
                  0
                  • hekH hek

                    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.

                    S Offline
                    S Offline
                    samppa
                    wrote on last edited by samppa
                    #16

                    @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..

                    1 Reply Last reply
                    0
                    • hekH Offline
                      hekH Offline
                      hek
                      Admin
                      wrote on last edited by hek
                      #17

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

                      A0 = 14
                      A1 = 15
                      ...

                      S 1 Reply Last reply
                      0
                      • hekH hek

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

                        A0 = 14
                        A1 = 15
                        ...

                        S Offline
                        S Offline
                        samppa
                        wrote on last edited by
                        #18

                        @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..

                        1 Reply Last reply
                        0
                        • 5546dug5 Offline
                          5546dug5 Offline
                          5546dug
                          wrote on last edited by
                          #19

                          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.

                          S 1 Reply Last reply
                          0
                          • 5546dug5 5546dug

                            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.

                            S Offline
                            S Offline
                            samppa
                            wrote on last edited by
                            #20

                            @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..

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            15

                            Online

                            11.7k

                            Users

                            11.2k

                            Topics

                            113.1k

                            Posts


                            Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • MySensors
                            • OpenHardware.io
                            • Categories
                            • Recent
                            • Tags
                            • Popular