Vera Plus and MySensors Local Serial Gateway



  • Hello.

    I have a problem and tried to search through the forum, but nothing found. So the problem is:

    1. I have both Arduino Nano V3 and Mega 2560 (all connected through FTDI chip)
    2. Uploaded some sketch for testing(found here)
    3. Installed Vera plugin from GitHub for UI7
    4. My Lib is 2.0.1-beta(latest from dev branch as I am working without NRF)
      Vera sees my FTDI, sees my Lib version and etc... Vera communicates with gateway fine:
    50	10/27/16 11:01:54.309	luup_log:129: Arduino plugin: loading library L_Arduino ... <0x7667f520>
    50	10/27/16 11:01:54.327	luup_log:129: Arduino plugin: library L_Arduino loaded <0x7667f520>
    50	10/27/16 11:01:54.328	luup_log:129: Arduino: urn:upnp-arduino-cc:serviceId:arduino1,PluginVersion, 1.5, 129 <0x7667f520>
    50	10/27/16 11:01:54.328	luup_log:129: Arduino: Trying for a serial connection <0x7667f520>
    50	10/27/16 11:01:54.328	luup_log:129: Arduino: Serial port is connected <0x7667f520>
    50	10/27/16 11:01:54.328	luup_log:129: Arduino: Baud is 115200 <0x7667f520>
    50	10/27/16 11:01:54.330	luup_log:129: Arduino: Sending: 0;0;3;0;2;Get Version <0x7667f520>
    50	10/27/16 11:01:55.687	luup_log:129: Arduino: Log: Gateway startup complete. <0x711d2520>
    50	10/27/16 11:01:55.688	luup_log:129: Arduino: Presentation: 0;255;0;0;17;2.0.1-beta <0x711d2520>
    50	10/27/16 11:01:55.688	luup_log:129: Arduino: Found new device 0;255 <0x711d2520>
    50	10/27/16 11:01:55.689	luup_log:129: Arduino: urn:upnp-arduino-cc:serviceId:arduino1,InclusionFoundCountHR, 1 devices found, 129 <0x711d2520>
    02	10/27/16 11:01:55.690	luup_log:129: Arduino: Incoming internal command '0;255;3;0;11;Arduino_USB' discarded for child: nil <0x711d2520>
    02	10/27/16 11:01:55.691	luup_log:129: Arduino: Incoming internal command '0;255;3;0;12;1.0' discarded for child: nil <0x711d2520>
    50	10/27/16 11:01:55.692	luup_log:129: Arduino: Presentation: 0;0;0;0;3;LED <0x711d2520>
    50	10/27/16 11:01:55.692	luup_log:129: Arduino: Found new device 0;0 <0x711d2520>
    50	10/27/16 11:01:55.692	luup_log:129: Arduino: urn:upnp-arduino-cc:serviceId:arduino1,InclusionFoundCountHR, 2 devices found, 129 <0x711d2520>
    50	10/27/16 11:01:55.693	luup_log:129: Arduino: Presentation: 0;1;0;0;3;RELE ASPERSOR PORCHE <0x711d2520>
    50	10/27/16 11:01:55.694	luup_log:129: Arduino: Found new device 0;1 <0x711d2520>
    50	10/27/16 11:01:55.694	luup_log:129: Arduino: urn:upnp-arduino-cc:serviceId:arduino1,InclusionFoundCountHR, 3 devices found, 129 <0x711d2520>
    50	10/27/16 11:01:55.695	luup_log:129: Arduino: Presentation: 0;2;0;0;3;RELE TURBINAS <0x711d2520>
    50	10/27/16 11:01:55.696	luup_log:129: Arduino: Found new device 0;2 <0x711d2520>
    50	10/27/16 11:01:55.696	luup_log:129: Arduino: urn:upnp-arduino-cc:serviceId:arduino1,InclusionFoundCountHR, 4 devices found, 129 <0x711d2520>
    50	10/27/16 11:01:55.697	luup_log:129: Arduino: Presentation: 0;3;0;0;3;RELE GOTEROS BAJOS <0x711d2520>
    50	10/27/16 11:01:55.698	luup_log:129: Arduino: Found new device 0;3 <0x711d2520>
    50	10/27/16 11:01:55.698	luup_log:129: Arduino: urn:upnp-arduino-cc:serviceId:arduino1,InclusionFoundCountHR, 5 devices found, 129 <0x711d2520>
    

    But after discovery of new devices nothing happens! Vera(or mysensors plugin) don't create new devices, just writes that 5 devices found! I have tried almost all combinations of Luup reset/Vera reset and etc.... After that I thought that problem is in sketch, connected gateway to Domoticz and got all 5 Devices...

    Please help!
    Thanks,
    and sorry for my english :)



  • Tried both Vera-dev and Vera-UI7 github channels.. no luck.. maybe the problem is in this lines:

    02	10/27/16 16:59:39.756	luup_log:133: Arduino: Incoming internal command '0;255;3;0;11;Arduino_USB' discarded for child: nil <0x717a6520>
    02	10/27/16 16:59:39.757	luup_log:133: Arduino: Incoming internal command '0;255;3;0;12;1.0' discarded for child: nil <0x717a6520>
    

    But cant handle and understand this errors...


  • Admin

    I haven't tried the Vera plugin with locally attached sensors. Took another look at the code but I can't see any reason why it shouldn't work.

    Might be good to introduce some more log-entries in the plugin lua code to see where it fails.

    Here:
    https://github.com/mysensors/Vera/blob/development/L_Arduino.lua#L328
    and here:
    https://github.com/mysensors/Vera/blob/development/L_Arduino.lua#L397



  • @hek said:

    https://github.com/mysensors/Vera/blob/development/L_Arduino.lua#L397

    Mmm, will try.. but I am new to LUA)) So will try to understand it.
    I am clicking start include and then reset my gateway, right?
    As you see the problem is in gateway inclusion and discarded commands



  • @hek

    And which branch I should use? development or UI7 ?


  • Admin

    Think they are the same at the moment.



  • @hek

    Still can't see in code why it get discarded.. Saw that there is discard for 1.0 versions in payload - changed to 2.0 in my sketch - no luck.

    Here is my sketch, look plz maybe somewhere is an error, but took here on forum from some member who has it working on Vera:

    
    // Enable debug prints to serial monitor
    //#define MY_DEBUG 
    
    
    // Enable and select radio type attached
    //Comento la siguiente linea para que no necesite radio
    //#define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Set LOW transmit power level as default, if you have an amplified NRF-module and
    // power your radio separately with a good regulator you can turn up PA level. 
    //#define MY_RF24_PA_LEVEL RF24_PA_LOW
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
    //#define MY_BAUD_RATE 9600
    
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    #define MY_INCLUSION_BUTTON_FEATURE
    
    // Inverses behavior of inclusion button (if using external pullup)
    //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
    
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 4  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  6  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  5  // the PCB, on board LED
    
    #include <SPI.h>
    #include <MySensors.h>  
    
    //Para el sensor de temperatura
    #ifdef TEMP
     #include <DallasTemperature.h>
     #include <OneWire.h>
     #define ONE_WIRE_BUS 2
     OneWire oneWire(ONE_WIRE_BUS);
     DallasTemperature sensors(&oneWire);
     MyMessage msg(0,V_TEMP);
    #endif
    
    //Structura de reles
    typedef struct  {
     int  pin;
     char desc[20];
     bool ON;
     bool OFF;
    } sRELE;
    
    sRELE Rele [] = { {13 , "LED", HIGH, LOW},
                     {31 , "RELE ASPERSOR PORCHE", LOW, HIGH},
                     {33 , "RELE TURBINAS", LOW, HIGH},
                     {35 , "RELE GOTEROS BAJOS", LOW, HIGH}
                   };
    
    #define NUMBER_OF_RELAYS 4 // Total number of attached relays
    
    void setup() { 
     // Setup locally attached sensors
    #ifdef TEMP
     //Para el sensor de temperatura
     sensors.begin();
    #endif
     //Para los reles
      // Serial.println("start call Setup");
     for (int sensor=0 ; sensor<NUMBER_OF_RELAYS;sensor++) {
       // Poner el rele en output mode
       pinMode(Rele[sensor].pin, OUTPUT);   
       // Poner el rele en el ultimo estado conocido (usando eeprom storage) 
       digitalWrite(Rele[sensor].pin, loadState(sensor)?Rele[sensor].ON:Rele[sensor].OFF);
     }
      // Serial.println("End call Setup");
      
    }
    
    void presentation() {
     // Presentar los sensores y actuadores locales 
     //Serial.println("start call presentation");
     // Mandar la info del sketch
    
     sendSketchInfo("myGateway", "2.0");
     //Presentar los reles
     for (int rele=0; rele<NUMBER_OF_RELAYS;rele++) {
       // Registrar todos los reles al gw
       present(rele, S_LIGHT,Rele[rele].desc);
     }
     //Serial.println("End call presentation");
    #ifdef TEMP
     //Presento el sensor de temperatura
     present(9,S_TEMP,"SENSOR_TEMP");
    #endif
    }
    bool STATUS;
    void loop() { 
     // Send locally attached sensor data here 
    #ifdef TEMP
    // Serial.print("Solicitando temperaturas...");
     sensors.requestTemperatures(); // Send the command to get temperatures
     float temperatura = sensors.getTempCByIndex(0);
     send(msg.setSensor(9).set(temperatura,1));
    // Serial.println("DONE");
     sleep(2000);
    #endif
    }
    
    
    void receive(const MyMessage &message) {
     // Solo esperamos mensajes V_LIGTH de momento, pero lo chequeamos por si acaso.
     if (message.type==V_LIGHT) {
        // Cambiar estado del rele
        digitalWrite(Rele[message.sensor].pin, message.getBool()?Rele[message.sensor].ON:Rele[message.sensor].OFF);
        // Almacenar estado en la eeprom
        saveState(message.sensor, message.getBool());
        // Escribir informacion de debug
       // Serial.print("Cambio entrante para sensor:");
       // Serial.print(message.sensor);
       // Serial.print(", Nuevo status: ");
        //Serial.println(message.getBool());
      } 
    }
    
    


  • As I understand the code, when I reset gateway and it was in inclusion mode - I get here:

    elseif (messageType==msgType.PRESENTATION) then
    log("Presentation: ".. s)
    presentation(incomingData, device, childId, altId)

    But I don't see any code in presentation function that belongs to creation of new device in Vera...
    I see creation at processInternalMessage, but it would not run as I get Presentation: 0;255;0;0;17;2.0.1-beta , but for inclusion it should be Presentation: 0;255;3;0;17;2.0.1-beta ? (message_type 3, not 0 as 0 do nothing with dev inclusion)


  • Admin

    Can't find any obvious error in the sketch.

    The creation process starts after inclusion mode ends.. see my link above.



  • @hek said:

    Can't find any obvious error in the sketch.

    The creation process starts after inclusion mode ends.. see my link above.

    Nope, I am sorry, but you are wrong... In case of local sensor it would not start(and I tested that with debug log in each function).
    Made some test function called processInclusion and now I got new devices listed) But because I am not a coder and don't know LUA - need to polish it a bit.
    The problem is that I need to push reset button on arduino, after that gateway send presentation BUT without internal type of message! So there is two ways:
    1 - make function for just inclusion process and put in right after presentation fujnction(pice of code from processInternal** function)
    2 - Make gateway to send some internal command right after presentation(not tested)

    First way tested, but I need to reset gateway same quantity of times as I have external sensors. So each new sensor is added after each reset.



  • (Edited post)

    Thought all night about my problem and it's solution... Just was one thought that dev's of mysensors plugin can't make mistake in old tested plugin) Reviewed plugin code once again and understood it's logic. So first we get called Presentation function which stores new devices in array and than we should get command from gateway about finished inclusion process and plugin start to add devices to Vera. So the problem is: when we don't use radio and only local sensors we don't get message about inclusion finish! )

    Solution is to send this message manually from gateway right after presentation processes. Should look like 0;255;3;0;5;0

    So I have added this lines to my Arduino sketch in presentation function:

    Serial.print("0;255;3;0;5;0");
      Serial.print("\n");
    

    This solution will work without coding to existing Vera plugin :)

    (Sorry, didn't found any other way to send this message like with MyMessage container)



  • @hek , maybe you could help to do that more right? And I think that this should be added to GitHub as a bug for 2.0.1-dev lib version (don't have an account on git)


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.