Serial Gateway connection to Openhab



  • I read on the comments for the Openhab Controller page (http://www.mysensors.org/build/openhab) that Tim is working on a serial gateway connection to Openhab. Is anyone else working on something like this?



  • @CARSTEN I'm running MySensors with OpenHab via Serial Gateway. You migth have a look at http://forum.mysensors.org/topic/301/the-best-way-to-connect-to-openhab/13. and/or http://forum.mysensors.org/topic/302/openhab-mqtt-tips-hints/6
    Until now (20 Nodes) the functions are very reliable. The backdraw is - you have to manage all replies in the codesection by yourself. It's an noticeable amount of (repetitive) coding, but offers also great flexibility.


  • Hero Member

    @CARSTEN I've compiled a modified version of the OpenHab Serial binding with a baud rate of 115200 as this is standard in mysensors.

    Download: org.openhab.binding.serial_1.6.0.201411271703.jar

    As @tboha suggested you currently have to manage all commands by yourself.

    I've attached my modified serial binding here. Please be aware, that all other configurations that depend on serial binding won't work with the modified version, because of the changed baud rate.

    I'm currently testing with this Serial Gateway:

    Serial Gateway

    Here is my OpenHab configuration for simple testing:

    demo.items: demo.items
    demo.rules: demo.rules
    demo.sitemap: demo.sitemap



  • @TimO Thanks a lot. I will definitely have a look at this. However I realized that I still have to go through quite a bit of a learning curve first. So I decided to first get the MQTT gateway woring and connecting to openhab.
    I will definitely come back to your solution later as it would give me a more minimalistic hardware approach.
    Thanks again.



  • @TimO Thank you Tim!

    I think i am on the right way but i couldnt change relay state. Please help me.

    Orginal sketch didnt worked for me (i dont have any temp-hum sensor and 2 relays yet) so i changed it to 1 relay without temp-hum

    here is my code;

    include <MySensor.h>
    include <SPI.h>

    define RELAY_1 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    define NUMBER_OF_RELAYS 1 // Total number of attached relays
    define RELAY_ON 1 // GPIO value to write to turn on attached relay
    define RELAY_OFF 0 // GPIO value to write to turn off attached relay

    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)

    MySensor gw(100);

    unsigned long lastCheckTime = millis();

    void setup()
    {
    // Initialize library and add callback for incoming messages
    gw.begin(incomingMessage, AUTO, true);
    // Send the sketch version information to the gateway and Controller
    gw.sendSketchInfo("Relay", "1.0");

    // Fetch relay status
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    gw.present(sensor, S_LIGHT);
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    //digitalWrite(pin, gw.loadState(sensor)?RELAY_ON:RELAY_OFF);
    digitalWrite(pin, RELAY_OFF);
    }

    //metric = gw.getConfig().isMetric;
    }

    void loop()
    {
    // Alway process incoming messages whenever possible
    gw.process();

    //gw.sleep(SLEEP_TIME); //sleep a bit
    }

    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.type==V_LIGHT) {
    // Change relay state
    digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
    gw.saveState(message.sensor, message.getBool());
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    }
    }

    and openhab;

    Launching the openHAB runtime...
    osgi> 2014-12-06 21:00:22.323 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.6.1).
    2014-12-06 21:00:23.266 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
    2014-12-06 21:00:23.301 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
    2014-12-06 21:00:25.171 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
    2014-12-06 21:00:32.963 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model '1.sitemap'
    2014-12-06 21:00:33.121 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'db4o.persist'
    2014-12-06 21:00:33.144 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'exec.persist'
    2014-12-06 21:00:33.150 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'logging.persist'
    2014-12-06 21:00:33.161 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist'
    2014-12-06 21:00:33.187 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model '1.items'
    2014-12-06 21:00:33.809 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /openhab.app
    2014-12-06 21:00:37.412 [INFO ] [.service.AbstractActiveService] - HTTP Refresh Service has been started
    2014-12-06 21:00:37.466 [INFO ] [.service.AbstractActiveService] - NTP Refresh Service has been started
    2014-12-06 21:00:38.892 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;14;Gateway startup complete.

    2014-12-06 21:00:43.265 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model '1.rules'
    2014-12-06 21:01:02.305 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 0-0-0 s=255,c=0,t=18,pt=0,l=5:1.4.1
    0;255;0;0;18;1.4.1
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=6,pt=1,l=1:0

    ArduinoUpdate -> 0;0;3;0;9;read: 0-0-0 s=255,c=0,t=18,pt=0,l=5:1.4.1
    0;255;0;0;18;1.4.1
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=6,pt=1,l=1:0
    2014-12-06 21:01:04.304 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 0-0-0 s=255,c=3,t=11,pt=0,l=5:Relay
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=12,pt=0,l=3:1.0
    0;0;3;0;9;read: 0-0-0 s=1,c=0,t=3,pt=0,l=5:1.4.1
    0;1;0;0;3;1.4.1

    ArduinoUpdate -> 0;0;3;0;9;read: 0-0-0 s=255,c=3,t=11,pt=0,l=5:Relay
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=12,pt=0,l=3:1.0
    0;0;3;0;9;read: 0-0-0 s=1,c=0,t=3,pt=0,l=5:1.4.1
    0;1;0;0;3;1.4.1
    2014-12-06 21:01:23.048 [INFO ] [runtime.busevents ] - RED_LED received command ON
    2014-12-06 21:01:23.130 [INFO ] [runtime.busevents ] - Arduino received command 100;1;1;0;2;1

    ArduinoUpdate -> 100;1;1;0;2;1
    2014-12-06 21:01:35.421 [INFO ] [runtime.busevents ] - RED_LED received command OFF
    2014-12-06 21:01:35.429 [INFO ] [runtime.busevents ] - Arduino received command 100;1;1;0;2;0

    ArduinoUpdate -> 100;1;1;0;2;0
    2014-12-06 21:02:02.885 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 0-0-0 s=255,c=0,t=18,pt=0,l=5:1.4.1
    0;255;0;0;18;1.4.1
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=6,pt=1,l=1:0

    ArduinoUpdate -> 0;0;3;0;9;read: 0-0-0 s=255,c=0,t=18,pt=0,l=5:1.4.1
    0;255;0;0;18;1.4.1
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=6,pt=1,l=1:0
    2014-12-06 21:02:04.991 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 0-0-0 s=255,c=3,t=11,pt=0,l=5:Relay
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=12,pt=0,l=3:1.0
    0;0;3;0;9;read: 0-0-0 s=1,c=0,t=3,pt=0,l=5:1.4.1
    0;1;0;0;3;1.4.1

    ArduinoUpdate -> 0;0;3;0;9;read: 0-0-0 s=255,c=3,t=11,pt=0,l=5:Relay
    0;0;3;0;9;read: 0-0-0 s=255,c=3,t=12,pt=0,l=3:1.0
    0;0;3;0;9;read: 0-0-0 s=1,c=0,t=3,pt=0,l=5:1.4.1
    0;1;0;0;3;1.4.1
    2014-12-06 21:03:31.097 [INFO ] [runtime.busevents ] - RED_LED received command ON
    2014-12-06 21:03:31.103 [INFO ] [runtime.busevents ] - Arduino received command 100;1;1;0;2;1

    ArduinoUpdate -> 100;1;1;0;2;1



  • @C.r.a.z.y. , maybe the Node-Id Delaration might be ineffektive. The output of OpenHab says your node identifies itself as Node 0 (Node 0 should be the Gateway itself). You should consider to give Static IDยดs like:
    #define NODE_ID 100
    gw.begin(incomingMessage, NODE_ID, true);

    So far I understand your sketch, yout try to assign a Node-id in the declaration statement

    MySensor gw(100);
    

    Iยดm not sure if this works. It will be safe to change it to

     MySensor gw();
    

    unless you got some very special hardware.

    If the Node-Id is assigned properly, your code example should work fine.



  • @tboha thank you!

    I tried motion sensor sketch (without any change) and it works. I also added motion to ui and i can see "motion" -"no motion" notifications.
    I will try relay again and give info.
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    **How can i add new devices automatically to UI OR add new device button in UI? - No touch to sitemap-items-rules etc files..

    More deeper : i have a "sensors" frame (like first floor in demo) and all sensors will be added to under this location OR how can i select which device will be added under x frame in UI? **



  • @C.r.a.z.y. OpenHab doesn't offer such methods like "inclusion" or search for unknown devices at the moment. But this is not due to MySensors properties, this is common to all bindings.
    Prerequisite for working with OpenHab seems to be the knowledge of your hardware to a very low level (e.g. programming the sensors yourself = MySensors). Accessing the configuration files results in great possibilities but also in much work.

    There is another User-Interface to this functions - https://github.com/cdjackson/HABmin - you might give this a try to get rid of the Eclipse-part of the OpenHab designer. I haven't tried it, but the slideshows are really impressive. Habmin may result in easier working -- but probably not in less work.

    You haven't told us what project you are aiming for - so it's a bit difficult to give a hint what may fit your needs.

    Regarding your last question, consider the following example:

    String HomeMaticS1 "Status1-1 [%s]"	<shield> (HomeMatic,kitchen, FirstFloor) {homematic="address=JEQ0459986, channel=1, parameter=LED_STATUS" }
    

    It is a String definition for my Homematic controlling one of 16 dual-color LEDs
    String denotes the type of this object
    HomematicS1 ist the name of this object.
    "Status1-1" ist the label displayed in the browser.,** [%s]** is a formating directive.
    **<shield> **is the name of the icon (which has to reside in \OpenHab1.6.1\webapps\images\shield.png --with exact this name)
    The round parenthesis **(Homematic, kitchen, FirstFloor) **tells Openhab to which group this object belongs --yes, one object may belong to many groups (= frames).

    The rest of this declaration implements the homematic binding with parameters you should know before - as mentioned above.

    The other 15 LEDControls are simply constructed by copy&paste and changing the numbers accordingly. Inconsistent numbering is a nice pitfall here and provides you with many happy hours.

    With the following Frame in the current .sitemap

     Frame label="MyFrame" {
    	Group item=HomeMatic icon="homematic"
    	Group item=kitchen icon="kitchen"
    	}
    

    Item **HomematicS1 ** will show up in both subframes labeled as "Status1-1".

    This applies to switches and other widgets in the same way, so you can operate your actors from within different frames.



  • @tboha Thank you for your detailed answer. ๐Ÿ‘



  • @C.r.a.z.y. Maybe the VERA controller is suitable for you. Have a look at http://forum.micasaverde.com/index.php, here especially http://forum.micasaverde.com/index.php/board,27.0.html. VERA has an inclusion mode and obviously supports Raspberry pi with Camera module (I didn't know before). Very probably you need additional additional hardware - I don'know if this is your intention.



  • @TimO said:

    @CARSTEN I've compiled a modified version of the OpenHab Serial binding with a baud rate of 115200 as this is standard in mysensors.

    Download: org.openhab.binding.serial_1.6.0.201411271703.jar

    As @tboha suggested you currently have to manage all commands by yourself.

    I've attached my modified serial binding here. Please be aware, that all other configurations that depend on serial binding won't work with the modified version, because of the changed baud rate.

    I'm currently testing with this Serial Gateway:

    Serial Gateway

    And a litte sensor/relay combination (switch LED on/off and read DHT22):

    RelayActuator

    Here is my OpenHab configuration for simple testing:

    demo.items: demo.items
    demo.rules: demo.rules
    demo.sitemap: demo.sitemap

    Tim did you modify this jar file? Where can i follow updates?
    1.6.1.jar version have arduino update problems


  • Hero Member

    @C.r.a.z.y. said:

    Tim did you modify this jar file? Where can i follow updates?
    1.6.1.jar version have arduino update problems

    Yes, I've modified the serial binding to work with mysensors.

    I've invested some work to solder a little serial mysensors gateway to test it's stability together with OpenHab. I've soldered two sockets (for an arduino nano and the nrf24l01+) on a perfboard. Currently there are only two sensors with dht22 connected, but everything works stable and smooth.

    Next step is to add two battery driven Atmega328p with dht22. I will build them from the scratch.

    I'm searching for a solution for the updates of the modified serial binding for OpenHab. My current idea is to commit a change to OpenHab, that allows to set the baudrate as a parameter, so I don't need to maintain updates by myself. Another solution could be a special mysensors binding. That would allow a few additional features, but needs to be maintained.

    Little Update:

    I've changed the Serial binding from OpenHab and commited a pull request. Let's see what the OpenHab developers think:

    https://github.com/openhab/openhab/pull/1897


  • Hero Member

    Problem solved, My pull request has been merged in the 1.7.0 branch.

    With the next version OpenHab supports the MySensors serial gateway with the serial binding out of the box.

    Baud rate parameter for example in demo.items:

    String Arduino "XXXXTemperature" { serial="/dev/ttyACM0@115200" }



  • Thank you for this great information. I have been setting up Openhab for the past month, and I've been trying different types of nodes using Moteino (Arduino clone) and RFM69 radios. I have also started building some scripts for Openhab to help streamline the receipt of serial messages. All of this is due to the great information I have found here and in other places on the forums.

    The one issue that has me frustrated is when I reboot OpenHab (I am currently using a headless raspberry pi). In order to get the sensors to work I have to unplug and re-plug in my gateway, and then run around the house and cycle power off and on to all my other nodes. Sometimes this works, and sometimes this doesn't work. Is there a reliable way to restart the serial gateway via software?

    I just did some more troubleshooting and noticed that when I fully reboot the entire raspberry pi, that it comes up correctly. However, sometimes I just want to exit and reboot openhab while I'm doing development.

    Once I find out how to make this part more reliable, the whole system will be working great! Thank you again for all of your very knowledgeable advice!


  • Hero Member

    @Matt-Perry
    I don't need to restart the serial gateway when I restart OpenHab.

    Do you use a static or auto node ids? I'm using static node ids. Maybe that is the reason you have to restart everything?

    When restarting OpenHab it outputs something like: "Removing stale Lockfile on "/dev/ttyACM0 .." and that's it.



  • @TimO

    I am giving the nodes static IDs. Here is an example of how I initialize an IR receiver/transmitter that I'm testing...

    #include <MySensor.h>
    #include <SPI.h>
    #include <IRLib.h>
    
    int RECV_PIN = 8;
    
    #define CHILD_1  3  // childId
    #define NODE_ID 101
    
    IRsend irsend;
    IRrecv irrecv(RECV_PIN);
    IRdecode decoder;
    //decode_results results;
    unsigned int Buffer[RAWBUF];
    MySensor gw;
    MyMessage msg(CHILD_1, V_VAR1);
     
    void setup()  
    {   
      irrecv.enableIRIn(); // Start the ir receiver
      decoder.UseExtnBuf(Buffer);
      //gw.begin(incomingMessage);
      gw.begin(incomingMessage, NODE_ID, true);
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("IR Sensor", "1.0");
     
     // Register a sensors to gw. Use binary light for test purposes.
     gw.present(CHILD_1, S_LIGHT);
    }
    

    Again, if I fully reboot my raspberry pi, it works (I am running Openhab as a startup script). But, if I want to troubleshoot a little bit, and "kill" the Openhab process and then call "start.sh" on the command line, the serial gateway does't reinitialize. Maybe I'm missing a step somewhere?

    If this problem only relates to me, I don't want to waste too much forum space. I could very possibly have something set up wrong on my end and I'll figure it out!

    Thanks!


  • Hero Member

    What did the OpenHab debug messages say?

    Did you check the permissions? Which user starts OpenHab with the startup script and which user do you use when you call "start.sh". Maybe there is a block because of the lock file? Kill the lock file (something like: "/var/lock/LCK..ttyUSB0") after killing OpenHab and before restarting with "start.sh".

    I'm currently not using a startup script, I'm using "start.sh" within a screen session, which I'm able to resume for debugging or to kill OpenHab.

    My network of MySensors nodes keeps working and reporting (temperature for example) and as soon as there is a controller running, the information is received.



  • @TimO

    Thanks again for the reply. Everything is working now. I believe the issue was with the serial connection moving to ttyUSB1. I'm not sure of why, or how, but I did create a SYMLINK and everything works just fine now, no matter what USB port the device is plugged into.

    Thanks again!



  • @TimO I tested your openHAB configuration and it is working fine most of the time. There is still one problem I was not able to fix. Some payloads have a dynamic length. Your example rules base on fixed length of the transmitted values, right?
    I tried to split the incoming strings with string.split("\n"), but the \n seems to be removed by openHAB or the serial gateway. Any ide how we can resolve this? Without this issue openHAB would work perfectly together with the serial gateway.



  • Hi

    I have the same problem with Matt and tried USB01 but didn't work.
    When i unplug the usb, server error : Write action failed! Input/output error2015-03-03 19:25:23.682 [ERROR] [b.serial.internal.SerialDevice] - Error writing '100;3;1;0;0;1
    ' to serial port /dev/ttyUSB0: Input/output error in writeArray

    Only solution for me stop server, unplug serial usb and plug it. I think ---Kill the lock file (something like: "/var/lock/LCK..ttyUSB0")--- will give the same solution like unplug the usb?



  • When i unplug and plug again the serial USB from raspberry :

    2015-03-04 20:27:56.413 [INFO ] [runtime.busevents ] - AP4 received command ON
    2015-03-04 20:27:56.564 [INFO ] [runtime.busevents ] - Arduino received command 100;1;1;0;0;1

    Write action failed! Input/output error2015-03-04 20:27:56.610 [ERROR] [b.serial.internal.SerialDevice] - Error writing '100;1;1;0;0;1
    ' to serial port /dev/ttyUSB0: Input/output error in writeArray

    How can fix this?



  • Why are you using a usb to serial adapter to connect the arduino to the raspberry? The raspberry hat an onboard uart at /dev/ttyAMA0. I am using the internal uart and cannot reproduce this kind of error.



  • Why are you using a usb to serial adapter to connect the arduino to the raspberry? The raspberry has an onboard uart at /dev/ttyAMA0. I am using the internal uart and cannot reproduce this kind of error.



  • @Jan-Gatzke said:

    ttyAMA0
    ๐Ÿ‘

    What version openhab runtime and add ons do you use?
    How many nodes do you have and how long time they are working fine without restart rpi?
    Please can you upload your config files?

    1.6.2 or 1.7.0 didn't switch on-off my relays but logs seems ok:

    I connected nano pins VIN+GND+TX+RX to RPI 5V+GND+TX+RX , (TX->TX , RX->RX)

    osgi> 2015-03-07 15:49:24.409 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.7.0).
    2015-03-07 15:49:50.387 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
    2015-03-07 15:49:51.200 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
    2015-03-07 15:50:01.540 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'default.items'
    2015-03-07 15:50:15.506 [WARN ] [cpr.DefaultAnnotationProcessor] - Unable to detect annotations. Application may fail to deploy.
    2015-03-07 15:50:17.567 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'default.sitemap'
    2015-03-07 15:50:32.786 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
    2015-03-07 15:50:38.947 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /openhab.app
    2015-03-07 15:50:51.918 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'default.rules'
    RXTX Warning: Removing stale lock file. /var/lock/LCK..ttyAMA0
    2015-03-07 15:51:01.398 [INFO ] [.service.AbstractActiveService] - NTP Refresh Service has been started

    2015-03-07 15:51:57.516 [INFO ] [runtime.busevents ] - S2 received command ON
    2015-03-07 15:52:08.006 [INFO ] [runtime.busevents ] - S2 received command OFF
    2015-03-07 15:52:11.408 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;0

    2015-03-07 15:52:11.722 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;1

    2015-03-07 15:52:19.544 [INFO ] [runtime.busevents ] - S1 received command ON
    2015-03-07 15:52:21.200 [INFO ] [runtime.busevents ] - Arduino received command 51;1;1;0;2;0

    2015-03-07 15:52:22.143 [INFO ] [runtime.busevents ] - S2 received command ON
    2015-03-07 15:52:22.259 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;0

    2015-03-07 15:52:23.131 [INFO ] [runtime.busevents ] - AP3 received command ON
    2015-03-07 15:52:24.142 [INFO ] [runtime.busevents ] - Arduino received command 100;3;1;0;0;1


  • Hero Member

    I've upgraded to the nightly of OpenHab 1.7.0 to see if I'm able to reproduce your problem.
    My modified OpenHab 1.6.2 did ran for a few weeks without problems. I'm using an Arduino Nano connected to an old laptop, so no RPi and the FTDI from the Nano.



  • @TimO please can you share Openhab files?
    +My relay powered from nano icp headers maybe this makes trouble for wifi , i will change this and give update.



  • @TimO

    I installed this https://github.com/lurch/rpi-serial-console
    pi@raspberrypi ~ $ rpi-serial-console status
    Serial console on /dev/ttyAMA0 is disabled

    Now my nodes are working perfect when i use manual button or ui but my logs are not correct

    My config:

    add on : org.openhab.binding.serial_1.6.0.201411271703.jar
    String Arduino "Arduino" { serial="/dev/ttyUSB0" }

    As you see there are "fails" but nodes are working.

    015-03-09 12:37:51.725 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1

    2015-03-09 12:37:56.726 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 52-52-0 s=255,c=0,t=18,pt=0,l=5:1.4.1
    52;255;0;0;18;1.4.1
    0;0;3;0;9;read: 52-52-0 s=255,c=3,t=6,pt=1,l=1:0
    52;255;3;0;6;0

    2015-03-09 12:37:58.768 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 52-52-0 s=255,c=3,t=11,pt=0,l=14:Relay & Button
    52;255;3;0;11;Relay & Button
    0;0;3;0;9;read: 52-52-0 s=255,c=3,t=12,pt=0,l=3:1.0
    52;255;3;0;12;1.0
    0;0;3;0;9;read: 52-52-0 s=1,c=0,t=3,pt=0,l=5:1.4.1
    52;1;0;0;3;1.4.1
    0;0;3;0;9;read: 52-52-0 s=2,c=0,t=3,pt=0,l=5:1.4.1
    52;2;0;0;3;1.4.1

    2015-03-09 12:37:59.700 [INFO ] [runtime.busevents ] - S2 received command ON
    2015-03-09 12:37:59.822 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;0

    2015-03-09 12:38:00.106 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:0

    2015-03-09 12:38:00.546 [INFO ] [runtime.busevents ] - S2 received command OFF
    2015-03-09 12:38:00.661 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;1

    2015-03-09 12:38:00.967 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1

    2015-03-09 12:38:01.161 [INFO ] [runtime.busevents ] - S2 received command ON
    2015-03-09 12:38:01.339 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;0

    2015-03-09 12:38:01.649 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:0

    2015-03-09 12:38:01.782 [INFO ] [runtime.busevents ] - S2 received command OFF
    2015-03-09 12:38:01.894 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;1

    2015-03-09 12:38:02.076 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1


  • Hero Member

    @C.r.a.z.y. : I don't think this problem is related to OpenHab.

    In my case the output looks like this:

    2015-03-09 11:50:45.780 [INFO ] [runtime.busevents             ] - Light_Corridor_First_Floor received command ON
    2015-03-09 11:50:45.782 [INFO ] [runtime.busevents             ] - Arduino received command 102;2;1;0;2;1
    
    ArduinoUpdate -> 102;2;1;0;2;1
    2015-03-09 11:50:45.990 [INFO ] [runtime.busevents             ] - Arduino state updated to 0;0;3;0;9;send: 0-0-102-102 s=2,c=1,t=2,pt=0,l=1,st=ok:1
    
    ArduinoUpdate -> 0;0;3;0;9;send: 0-0-102-102 s=2,c=1,t=2,pt=0,l=1,st=ok:1
    

    OpenHab does not interpret the response (fail/ok). It is something I need to work on.



  • @TimO I think so maybe rpi usb problem...

    Is there a newer file for org.openhab.binding.serial_1.6.0.201411271703


  • Hero Member

    @C.r.a.z.y.: Yes, I'm using the current NIGHTLY from cloudbees: https://openhab.ci.cloudbees.com/job/openHAB/

    You need to change:

    String Arduino "Arduino" { serial="/dev/ttyUSB0" }
    

    To:

    String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }
    

    The communication between the Gateway and the Controller/OpenHab seems to work fine, but the answer from the Gateway is the wrong one. So changing the binding won't solve this problem.

    What is the serial output of the receiving node?



  • @tim @hek
    Hek adviced me to download current 1.4 v in a topic and i did. I was using 1.4 which downloaded 2 months ago.
    After that;
    My old node's sketch(or api) was not the same with my new serial controller sketch 1.4
    I reupload sketches to every node and gateway still I am not sure with this solution but today my nodes worked fine.



  • Hi all,
    I wrote some rules for serial gateway to openhab, temp, hum, switch, dimmer and some internal commands are working without a problem. I don't have too much time to develop this for other devices.
    I'm not a java programmer so if I made some mistakes feel free to comment.
    The goal is to write a rules that will be easily expanded to other devices.
    I create a has map table where I define mappings ID to item name and inversely.
    test.rules file:

    import org.openhab.core.library.types.*
    import org.openhab.core.persistence.*
    import org.openhab.model.script.actions.*
    import java.util.*
    import org.eclipse.xtext.xbase.lib.*
    import org.openhab.core.items.*
    
    var String ArduinoUpdate = ""
    var String sketchName = ""
    var int V_TEMP = 0
    var int V_HUM = 1
    var int V_LIGHT = 2
    var int V_DIMMER = 3
    var int V_PRESSURE = 4
    var int V_FORECAST = 5
    var int V_RAIN = 6
    var int V_RAINRATE = 7
    var int V_WIND = 8
    var int V_GUST = 9
    var int V_DIRECTION = 10
    var int V_UV = 11
    var int V_WEIGHT = 12
    var int V_DISTANCE = 13
    var int V_IMPEDANCE = 14
    var int V_ARMED = 15
    var int V_TRIPPED = 16
    var int V_WATT = 17
    var int V_KWH = 18
    var int V_SCENE_ON = 19
    var int V_SCENE_OFF = 20
    var int V_HEATER = 21
    var int V_HEATER_SW = 22
    var int V_LIGHT_LEVEL = 23
    var int V_VAR1 = 24
    var int V_VAR2 = 25
    var int V_VAR3 = 26
    var int V_VAR4 = 27
    var int V_VAR5 = 28
    var int V_UP = 29
    var int V_DOWN = 30
    var int V_STOP = 31
    var int V_IR_SEND = 32
    var int V_IR_RECEIVE = 33
    var int V_FLOW = 34
    var int V_VOLUME = 35
    var int V_LOCK_STATUS = 36
    var int V_DUST_LEVEL = 37
    var int V_VOLTAGE = 38
    var int V_CURRENT = 39
    var int msgPresentation = 0
    var int msgSet = 1
    var int msgReq = 2
    var int msgInternal = 3
    var int msgStream = 4
    var int alarmArmor = 1
    // Internal Commands
    
    var int I_BATTERY_LEVEL = 0
    var int I_TIME = 1
    var int I_VERSION = 2
    var int I_ID_REQUEST = 3
    var int I_ID_RESPONSE = 4
    var int I_INCLUSION_MODE = 5
    var int I_CONFIG = 6
    var int I_FIND_PARENT = 7
    var int I_FIND_PARENT_RESPONSE = 8
    var int I_LOG_MESSAGE = 9
    var int I_CHILDREN = 10
    var int I_SKETCH_NAME = 11
    var int I_SKETCH_VERSION = 12
    var int I_REBOOT = 13
    var int I_GATEWAY_READY = 14
    // Mappings
    var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
    	"21;1;" -> "tempSalon01", 
    	"tempSalon01" -> "21;1;",
    	"21;0;" -> "humSalon01", 
    	"humSalon01" -> "21;0;",
    	"22;0;" -> "plugStrip01s12", 
    	"plugStrip01s12" -> "22;0;",
    	"22;1;" -> "plugStrip01s34", 
    	"plugStrip01s34" -> "22;1;",
    	"20;0;" -> "lightSalonCeiling00", 
    	"lightSalonCeiling00" -> "20;0;",
    	"20;1;" -> "lightSalonCeiling01", 
    	"lightSalonCeiling01" -> "20;1;",
    	"20;2;" -> "lightSalonCeiling02", 
    	"lightSalonCeiling02" -> "20;2;",
    	"20;3;" -> "lightSalonCeiling03", 
    	"lightSalonCeiling03" -> "20;3;",
    	"20;4;" -> "lightSalonCeiling04", 
    	"lightSalonCeiling04" -> "20;4;",
    	"10;4;" -> "lightBar04", 
    	"lightBar04" -> "10;4;",
    	"10;0;" -> "lightKitchenCabinet00", 
    	"lightKitchenCabinet00" -> "10;0;",
    	"10;1;" -> "lightKitchenCabinet01", 
    	"lightKitchenCabinet01" -> "10;1;",
    	"10;2;" -> "lightKitchenCabinet02", 
    	"lightKitchenCabinet02" -> "10;2;",
    	"10;3;" -> "lightKitchenCabinet03", 
    	"lightKitchenCabinet03" -> "10;3;",
    	"20;255;" -> "sensorLRCDimmer", 
    	"21;255;" -> "sensorLRHumTemp", 
    	"22;255;" -> "sensorLRStripPlug01", 
    	"10;255;" -> "sensorKCLight"
    
    )
    // dimmer function
    val org.eclipse.xtext.xbase.lib.Functions$Function5 dimmerOperation = [
    	org.openhab.core.library.items.DimmerItem relayItem, 
    	org.openhab.core.library.items.StringItem arduinoItem, 
    	String arduinoDevMap,
    	String receivedCommand,
    	Integer subType|
    	var Number percent = 0
    	if(relayItem.state instanceof DecimalType) percent = relayItem.state as DecimalType
    	if(receivedCommand==INCREASE) percent = percent + 5
    	if(receivedCommand==DECREASE) percent = percent - 5
    	if(receivedCommand==ON) percent = 100       
    	if(receivedCommand==OFF) percent = 0        
    	if(percent<0)   percent = 0
    	if(percent>100) percent = 100
    	
    	println ("Function: dimmerOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + percent )
    	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + percent + "\n")
    ]
    //switch function
    val org.eclipse.xtext.xbase.lib.Functions$Function4 switchOperation = [
    	org.openhab.core.library.items.SwitchItem relayItem, 
    	org.openhab.core.library.items.StringItem arduinoItem, 
    	String arduinoDevMap,
    	Integer subType|
    	var Integer state = 0
            if (relayItem.state == OFF) {
    		state = 0 
    	}
    	else {
    		state = 1
    	}
    	println ("Function: switchOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + state )
    	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + state + "\n")
    ]
    
    //receiving msg from mysensors gateway
    rule "Arduino sends to Openhab"
    	when
    		Item Arduino received update
    	then
    		var String lineBuffer =  Arduino.state.toString.split("\n")
    		for (String line : lineBuffer) {
    			var String[] message = line.split(";")
    			var Integer nodeId = new Integer(message.get(0))
    			var Integer childId = new Integer(message.get(1))
    			var Integer msgType = new Integer(message.get(2))
    			var Integer ack = new Integer(message.get(3))
    			var Integer subType = new Integer(message.get(4))
    			var String msg = message.get(5)
    			if(msgType == 1 ){
    				if (subType == V_TEMP){
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    					println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
    					}
    				if (subType == V_HUM){
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    					println ("HUM item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
    					}
    				if (subType == V_DIMMER){
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    					println ("Dimmer item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Dimmer: " + msg )
    						}
    				if (subType == V_LIGHT){
    					var String state
    					var Integer statusInt = new Integer(message.get(5))
    					if(statusInt == 1) { 
    						state = "ON"
    						} 
    					else { 
    						state = "OFF" 
    						}
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), state)
    					println ("Light Item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Light: " + state )
    					}
    				}
    			// Internal Command
    			if(msgType == 3){
    				if(subType == I_SKETCH_NAME){
    						println("Sketch name: " + msg )
    						sketchName=msg
    					}
    				if(subType == I_SKETCH_VERSION){
    						println("Sketch version: " + msg )
    						postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), sketchName+" " +msg )
    						sketchName=""
    					}
    				}
    			}	
    		}
    end
    
    
    
    rule "lightBar04 Switch Rule"
    	when
    		Item lightBar04 changed
    	then
    		switchOperation.apply(lightBar04, Arduino, sensorToItemsMap.get("lightBar04"), V_LIGHT)			
    end	
    
    rule "lightKitchenCabinet00 Switch Rule"
    	when
    		Item lightKitchenCabinet00 changed
    	then
    		switchOperation.apply(lightKitchenCabinet00, Arduino, sensorToItemsMap.get("lightKitchenCabinet00"), V_LIGHT)			
    end	
    
    rule "lightKitchenCabinet01 Switch Rule"
    	when
    		Item lightKitchenCabinet01 changed
    	then
    		switchOperation.apply(lightKitchenCabinet01, Arduino, sensorToItemsMap.get("lightKitchenCabinet01"), V_LIGHT)			
    end	
    
    rule "lightKitchenCabinet02 Switch Rule"
    	when
    		Item lightKitchenCabinet02 changed
    	then
    		switchOperation.apply(lightKitchenCabinet02, Arduino, sensorToItemsMap.get("lightKitchenCabinet02"), V_LIGHT)			
    end	
    
    rule "lightKitchenCabinet03 Switch Rule"
    	when
    		Item lightKitchenCabinet03 changed
    	then
    		switchOperation.apply(lightKitchenCabinet03, Arduino, sensorToItemsMap.get("lightKitchenCabinet03"), V_LIGHT)			
    end	
    
    rule "lightSalonCeiling00 Switch Rule"
    	when
    		Item lightSalonCeiling00 received command
    	then
    		if(lightSalonCeiling00.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling00, Arduino, sensorToItemsMap.get("lightSalonCeiling00"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    rule "lightSalonCeiling01 Switch Rule"
    	when
    		Item lightSalonCeiling01 received command
    	then
    		if(lightSalonCeiling01.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling01, Arduino, sensorToItemsMap.get("lightSalonCeiling01"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    rule "lightSalonCeiling02 Switch Rule"
    	when
    		Item lightSalonCeiling02 received command
    	then
    		if(lightSalonCeiling02.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling02, Arduino, sensorToItemsMap.get("lightSalonCeiling02"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    rule "lightSalonCeiling03 Switch Rule"
    	when
    		Item lightSalonCeiling03 received command
    	then
    		if(lightSalonCeiling03.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling03, Arduino, sensorToItemsMap.get("lightSalonCeiling03"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    rule "lightSalonCeiling04 Switch Rule"
    	when
    		Item lightSalonCeiling04 received command
    	then
    		if(lightSalonCeiling04.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling04, Arduino, sensorToItemsMap.get("lightSalonCeiling04"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    
    rule "plugStrip01s12 Switch Rule"
    	when
    		Item plugStrip01s12 changed
    	then
    		switchOperation.apply(plugStrip01s12, Arduino, sensorToItemsMap.get("plugStrip01s12"), V_LIGHT)			
    end	
    
    
    rule "plugStrip01s34 Switch Rule"
    	when
    		Item plugStrip01s34 changed
    	then
    		switchOperation.apply(plugStrip01s34, Arduino, sensorToItemsMap.get("plugStrip01s34"), V_LIGHT)			
    end	
    

    my test.item

    String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }
    Group All
    Group flat "Flat" <house>
    Group livingRoom "Living Room"  <sofa>  (All,flat)
    Group kitchen      "Kitchen" <kitchen>  (All,flat)
    Group corridor      "Corridor" <corridor>  (All,flat)
    Group bathroom      "Bathroom" <bath>  (All,flat)
    Group gmRoom  "Grandma Room" <smile>  (All,flat)
    Group weather   (All)
    Group status    (All)
    Group mysensors    (All)
    
    Group:Switch:OR(ON, OFF) kLights "Lights" <light> (All, kitchen)
    Group:Switch:OR(ON, OFF) kcLights "Cabinet Lights [(%d)]" <light> (All, kLights)
    Group:Switch:OR(ON, OFF) skcLights "Single Cabinet Lights [(%d)]" <light> (All)
    
    Group:Switch:OR(ON, OFF) lrLights "Lights" <light> (livingRoom)
    Group:Switch:OR(ON, OFF) lrcLights "Ceiling Lights [(%d)]" <light> (lrLights)
    
    Group:Switch:OR(ON, OFF) lrSockets "Sockets" <socket> (livingRoom)
    Group:Switch:OR(ON, OFF) lrPlugStrip "Sockets [(%d)]" <socket> (lrSockets)
    
    Group:Number:AVG humAndTemp "Avg. Room Humidity[%.1f %%] and Temperature [%.1f ยฐC]" <temperature>
    Group:Number:AVG temperature "Avg. Room Temperature [%.1f ยฐC]" <temperature> (status)
    Group:Number:AVG humidity "Avg. Room Humidity [%.1f %%]" <temperature> (status)
    
    
    Group:Switch:OR(ON, OFF) lights "All Lights [(%d)]" <light> (All)
    
    Number tempChartPeriod          "Chart Period"
    Number tempSalon01 "Temperature [%s ยฐC]" <temperature> (temperature,humAndTemp)
    Number humSalon01 "Humidity [%s %%]" <temperature> (humidity,humAndTemp)
    Switch lightKitchenCabinet00	"Light 1" (lights, kcLights)
    Switch lightKitchenCabinet01	"Light 2" (lights, kcLights)
    Switch lightKitchenCabinet02	"Light 3" (lights, kcLights)
    Switch lightKitchenCabinet03	"Light 4" (lights, kcLights)
    
    Switch lightBar04		"Bar Lights" (lights, kLights, lrLights)
    
    Dimmer lightSalonCeiling00	"Light 1 [%s %%]" (lights, lrcLights)
    Dimmer lightSalonCeiling01	"Light 2 [%s %%]" (lights, lrcLights)
    Dimmer lightSalonCeiling02	"Light 3 [%s %%]" (lights, lrcLights)
    Dimmer lightSalonCeiling03	"Light 4 [%s %%]" (lights, lrcLights)
    Dimmer lightSalonCeiling04	"Light All [%s %%]" (lights,lrLights,allLights)
    Switch plugStrip01s12		"Sockets 1-2" <socket> (lrPlugStrip)
    Switch plugStrip01s34		"Sockets 3-4" <socket> (lrPlugStrip)
    
    String sensorLRCDimmer "Living Room Ceiling Light Sensor [%s]" (mysensors)
    String sensorLRStripPlug01 "Living Room Strip Plug 01 Sensor [%s]" (mysensors)
    String sensorLRHumTemp "Living Room Hum&Temp&Motion&Light  Sensor [%s]" (mysensors)
    String sensorKCLight "Kitchen&Bar Light Sensor [%s]" (mysensors)
    

    my test.sitemap

    sitemap demo label="Main Menu"
    {
    
    	Frame label="Home" {
    		Group label="Kitchen" icon="kitchen" {
    			Frame label="Kitchen" {
    				Group item=kLights label="Lights" {
    				Switch item=lightBar04 label="Bar Lights"
    				Switch item=kcLights label="Cabinet Lights"
    				Group item=kcLights 
    				}
    			}
    		}
    
    		Group item=livingRoom {
    			Frame label="Living Room" {
    				Group item=lrLights 
    				Group label="Sensors" icon="temperature" {
    					Text item=tempSalon01 valuecolor=[tempSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
    					Text item=humSalon01 valuecolor=[humSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
    					Switch item=tempChartPeriod label="Chart Period" mappings=[0="12 Hours", 1="Day", 2="Week", 3="Month"]
    					Chart item=humAndTemp period=12h refresh=5000 visibility=[tempChartPeriod==0,tempChartPeriod=="Uninitialized"]
    					Chart item=humAndTemp period=D refresh=1800 visibility=[tempChartPeriod==1]
    					Chart item=humAndTemp period=W refresh=3600 visibility=[tempChartPeriod==2]
    					Chart item=humAndTemp period=M refresh=7200 visibility=[tempChartPeriod==3]
    				}
    				Group item=lrPlugStrip
    			}
    		}
    		Group item=corridor 
    		Group item=bathroom icon="bath"
    		Group item=grandmotherRoom icon="smiley"
    	}
    
    	Frame label="Lights All"{
    		Switch item=lights mappings=[OFF="All Off"]
    		Group item=lights
    		Group item=mysensors
    	}
    

  • Hero Member

    Cool! I will certainly adapt that! Thanks!



  • This looks great. Far better than my rules. I like the approach with the hash table very much.



  • Can I get the Arduino uno code for this openhab serial binding?
    I want a like to see that how it will work.


  • Hero Member

    @jemish : Just use this one: http://www.mysensors.org/build/serial_gateway

    It is the standard serial gateway. Nothing special.



  • At this link: http://www.mysensors.org/build/serial_gateway I got the arduino sketch,
    but I want to know, this sketch is for main arduino that is connected to the raspberry pi via serial communication and other side it is connected to the nRF24L01.

    If it is true than, I want to know which code is required at node side where I can ON or OFF LED and LIGHTS or DIMMER.



  • Hey.....please can anyone reply me?......please......



  • @jemish This is to basic to earn an answer. I suggest you start reading at http://www.mysensors.org .



  • hi,
    I have a question, that how can I get feedback from our switchboard that is at our wall.

    If I am on the light by pressing the switch at switchboard.

    If in case I get the 5v from switchboard and give it to the Arduino, than how can I update state of switch in openhab.



  • Hay, can any one try that.........feedback from switchboard


  • Hero Member

    I would try to use something like this on the sensor connected to the switchboard:

    http://www.mysensors.org/build/binary

    This will send V_TRIPPED per default.

    In the rules files you have to bring everything togehter:

    if V_TRIPPED from sensor_id_xyz received
    then update status of light switch

    If you know what I mean. ๐Ÿ˜„



  • This post is deleted!


  • @l154 said:

    Hi all,
    I wrote some rules for serial gateway to openhab, temp, hum, switch, dimmer and some internal commands are working without a problem. I don't have too much time to develop this for other devices.
    I'm not a java programmer so if I made some mistakes feel free to comment.
    The goal is to write a rules that will be easily expanded to other devices.
    I create a has map table where I define mappings ID to item name and inversely.
    test.rules file:

    import org.openhab.core.library.types.*
    import org.openhab.core.persistence.*
    import org.openhab.model.script.actions.*
    import java.util.*
    import org.eclipse.xtext.xbase.lib.*
    import org.openhab.core.items.*
    
    var String ArduinoUpdate = ""
    var String sketchName = ""
    var int V_TEMP = 0
    var int V_HUM = 1
    var int V_LIGHT = 2
    var int V_DIMMER = 3
    var int V_PRESSURE = 4
    var int V_FORECAST = 5
    var int V_RAIN = 6
    var int V_RAINRATE = 7
    var int V_WIND = 8
    var int V_GUST = 9
    var int V_DIRECTION = 10
    var int V_UV = 11
    var int V_WEIGHT = 12
    var int V_DISTANCE = 13
    var int V_IMPEDANCE = 14
    var int V_ARMED = 15
    var int V_TRIPPED = 16
    var int V_WATT = 17
    var int V_KWH = 18
    var int V_SCENE_ON = 19
    var int V_SCENE_OFF = 20
    var int V_HEATER = 21
    var int V_HEATER_SW = 22
    var int V_LIGHT_LEVEL = 23
    var int V_VAR1 = 24
    var int V_VAR2 = 25
    var int V_VAR3 = 26
    var int V_VAR4 = 27
    var int V_VAR5 = 28
    var int V_UP = 29
    var int V_DOWN = 30
    var int V_STOP = 31
    var int V_IR_SEND = 32
    var int V_IR_RECEIVE = 33
    var int V_FLOW = 34
    var int V_VOLUME = 35
    var int V_LOCK_STATUS = 36
    var int V_DUST_LEVEL = 37
    var int V_VOLTAGE = 38
    var int V_CURRENT = 39
    var int msgPresentation = 0
    var int msgSet = 1
    var int msgReq = 2
    var int msgInternal = 3
    var int msgStream = 4
    var int alarmArmor = 1
    // Internal Commands
    
    var int I_BATTERY_LEVEL = 0
    var int I_TIME = 1
    var int I_VERSION = 2
    var int I_ID_REQUEST = 3
    var int I_ID_RESPONSE = 4
    var int I_INCLUSION_MODE = 5
    var int I_CONFIG = 6
    var int I_FIND_PARENT = 7
    var int I_FIND_PARENT_RESPONSE = 8
    var int I_LOG_MESSAGE = 9
    var int I_CHILDREN = 10
    var int I_SKETCH_NAME = 11
    var int I_SKETCH_VERSION = 12
    var int I_REBOOT = 13
    var int I_GATEWAY_READY = 14
    // Mappings
    var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
    	"21;1;" -> "tempSalon01", 
    	"tempSalon01" -> "21;1;",
    	"21;0;" -> "humSalon01", 
    	"humSalon01" -> "21;0;",
    	"22;0;" -> "plugStrip01s12", 
    	"plugStrip01s12" -> "22;0;",
    	"22;1;" -> "plugStrip01s34", 
    	"plugStrip01s34" -> "22;1;",
    	"20;0;" -> "lightSalonCeiling00", 
    	"lightSalonCeiling00" -> "20;0;",
    	"20;1;" -> "lightSalonCeiling01", 
    	"lightSalonCeiling01" -> "20;1;",
    	"20;2;" -> "lightSalonCeiling02", 
    	"lightSalonCeiling02" -> "20;2;",
    	"20;3;" -> "lightSalonCeiling03", 
    	"lightSalonCeiling03" -> "20;3;",
    	"20;4;" -> "lightSalonCeiling04", 
    	"lightSalonCeiling04" -> "20;4;",
    	"10;4;" -> "lightBar04", 
    	"lightBar04" -> "10;4;",
    	"10;0;" -> "lightKitchenCabinet00", 
    	"lightKitchenCabinet00" -> "10;0;",
    	"10;1;" -> "lightKitchenCabinet01", 
    	"lightKitchenCabinet01" -> "10;1;",
    	"10;2;" -> "lightKitchenCabinet02", 
    	"lightKitchenCabinet02" -> "10;2;",
    	"10;3;" -> "lightKitchenCabinet03", 
    	"lightKitchenCabinet03" -> "10;3;",
    	"20;255;" -> "sensorLRCDimmer", 
    	"21;255;" -> "sensorLRHumTemp", 
    	"22;255;" -> "sensorLRStripPlug01", 
    	"10;255;" -> "sensorKCLight"
    
    )
    // dimmer function
    val org.eclipse.xtext.xbase.lib.Functions$Function5 dimmerOperation = [
    	org.openhab.core.library.items.DimmerItem relayItem, 
    	org.openhab.core.library.items.StringItem arduinoItem, 
    	String arduinoDevMap,
    	String receivedCommand,
    	Integer subType|
    	var Number percent = 0
    	if(relayItem.state instanceof DecimalType) percent = relayItem.state as DecimalType
    	if(receivedCommand==INCREASE) percent = percent + 5
    	if(receivedCommand==DECREASE) percent = percent - 5
    	if(receivedCommand==ON) percent = 100       
    	if(receivedCommand==OFF) percent = 0        
    	if(percent<0)   percent = 0
    	if(percent>100) percent = 100
    	
    	println ("Function: dimmerOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + percent )
    	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + percent + "\n")
    ]
    //switch function
    val org.eclipse.xtext.xbase.lib.Functions$Function4 switchOperation = [
    	org.openhab.core.library.items.SwitchItem relayItem, 
    	org.openhab.core.library.items.StringItem arduinoItem, 
    	String arduinoDevMap,
    	Integer subType|
    	var Integer state = 0
            if (relayItem.state == OFF) {
    		state = 0 
    	}
    	else {
    		state = 1
    	}
    	println ("Function: switchOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + state )
    	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + state + "\n")
    ]
    
    //receiving msg from mysensors gateway
    rule "Arduino sends to Openhab"
    	when
    		Item Arduino received update
    	then
    		var String lineBuffer =  Arduino.state.toString.split("\n")
    		for (String line : lineBuffer) {
    			var String[] message = line.split(";")
    			var Integer nodeId = new Integer(message.get(0))
    			var Integer childId = new Integer(message.get(1))
    			var Integer msgType = new Integer(message.get(2))
    			var Integer ack = new Integer(message.get(3))
    			var Integer subType = new Integer(message.get(4))
    			var String msg = message.get(5)
    			if(msgType == 1 ){
    				if (subType == V_TEMP){
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    					println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
    					}
    				if (subType == V_HUM){
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    					println ("HUM item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
    					}
    				if (subType == V_DIMMER){
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    					println ("Dimmer item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Dimmer: " + msg )
    						}
    				if (subType == V_LIGHT){
    					var String state
    					var Integer statusInt = new Integer(message.get(5))
    					if(statusInt == 1) { 
    						state = "ON"
    						} 
    					else { 
    						state = "OFF" 
    						}
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), state)
    					println ("Light Item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Light: " + state )
    					}
    				}
    			// Internal Command
    			if(msgType == 3){
    				if(subType == I_SKETCH_NAME){
    						println("Sketch name: " + msg )
    						sketchName=msg
    					}
    				if(subType == I_SKETCH_VERSION){
    						println("Sketch version: " + msg )
    						postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), sketchName+" " +msg )
    						sketchName=""
    					}
    				}
    			}	
    		}
    end
    
    
    
    rule "lightBar04 Switch Rule"
    	when
    		Item lightBar04 changed
    	then
    		switchOperation.apply(lightBar04, Arduino, sensorToItemsMap.get("lightBar04"), V_LIGHT)			
    end	
    
    rule "lightKitchenCabinet00 Switch Rule"
    	when
    		Item lightKitchenCabinet00 changed
    	then
    		switchOperation.apply(lightKitchenCabinet00, Arduino, sensorToItemsMap.get("lightKitchenCabinet00"), V_LIGHT)			
    end	
    
    rule "lightKitchenCabinet01 Switch Rule"
    	when
    		Item lightKitchenCabinet01 changed
    	then
    		switchOperation.apply(lightKitchenCabinet01, Arduino, sensorToItemsMap.get("lightKitchenCabinet01"), V_LIGHT)			
    end	
    
    rule "lightKitchenCabinet02 Switch Rule"
    	when
    		Item lightKitchenCabinet02 changed
    	then
    		switchOperation.apply(lightKitchenCabinet02, Arduino, sensorToItemsMap.get("lightKitchenCabinet02"), V_LIGHT)			
    end	
    
    rule "lightKitchenCabinet03 Switch Rule"
    	when
    		Item lightKitchenCabinet03 changed
    	then
    		switchOperation.apply(lightKitchenCabinet03, Arduino, sensorToItemsMap.get("lightKitchenCabinet03"), V_LIGHT)			
    end	
    
    rule "lightSalonCeiling00 Switch Rule"
    	when
    		Item lightSalonCeiling00 received command
    	then
    		if(lightSalonCeiling00.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling00, Arduino, sensorToItemsMap.get("lightSalonCeiling00"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    rule "lightSalonCeiling01 Switch Rule"
    	when
    		Item lightSalonCeiling01 received command
    	then
    		if(lightSalonCeiling01.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling01, Arduino, sensorToItemsMap.get("lightSalonCeiling01"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    rule "lightSalonCeiling02 Switch Rule"
    	when
    		Item lightSalonCeiling02 received command
    	then
    		if(lightSalonCeiling02.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling02, Arduino, sensorToItemsMap.get("lightSalonCeiling02"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    rule "lightSalonCeiling03 Switch Rule"
    	when
    		Item lightSalonCeiling03 received command
    	then
    		if(lightSalonCeiling03.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling03, Arduino, sensorToItemsMap.get("lightSalonCeiling03"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    rule "lightSalonCeiling04 Switch Rule"
    	when
    		Item lightSalonCeiling04 received command
    	then
    		if(lightSalonCeiling04.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
    		dimmerOperation.apply(lightSalonCeiling04, Arduino, sensorToItemsMap.get("lightSalonCeiling04"), receivedCommand, V_DIMMER)			
    		} 
    	end	
    
    rule "plugStrip01s12 Switch Rule"
    	when
    		Item plugStrip01s12 changed
    	then
    		switchOperation.apply(plugStrip01s12, Arduino, sensorToItemsMap.get("plugStrip01s12"), V_LIGHT)			
    end	
    
    
    rule "plugStrip01s34 Switch Rule"
    	when
    		Item plugStrip01s34 changed
    	then
    		switchOperation.apply(plugStrip01s34, Arduino, sensorToItemsMap.get("plugStrip01s34"), V_LIGHT)			
    end	
    

    my test.item

    String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }
    Group All
    Group flat "Flat" <house>
    Group livingRoom "Living Room"  <sofa>  (All,flat)
    Group kitchen      "Kitchen" <kitchen>  (All,flat)
    Group corridor      "Corridor" <corridor>  (All,flat)
    Group bathroom      "Bathroom" <bath>  (All,flat)
    Group gmRoom  "Grandma Room" <smile>  (All,flat)
    Group weather   (All)
    Group status    (All)
    Group mysensors    (All)
    
    Group:Switch:OR(ON, OFF) kLights "Lights" <light> (All, kitchen)
    Group:Switch:OR(ON, OFF) kcLights "Cabinet Lights [(%d)]" <light> (All, kLights)
    Group:Switch:OR(ON, OFF) skcLights "Single Cabinet Lights [(%d)]" <light> (All)
    
    Group:Switch:OR(ON, OFF) lrLights "Lights" <light> (livingRoom)
    Group:Switch:OR(ON, OFF) lrcLights "Ceiling Lights [(%d)]" <light> (lrLights)
    
    Group:Switch:OR(ON, OFF) lrSockets "Sockets" <socket> (livingRoom)
    Group:Switch:OR(ON, OFF) lrPlugStrip "Sockets [(%d)]" <socket> (lrSockets)
    
    Group:Number:AVG humAndTemp "Avg. Room Humidity[%.1f %%] and Temperature [%.1f ยฐC]" <temperature>
    Group:Number:AVG temperature "Avg. Room Temperature [%.1f ยฐC]" <temperature> (status)
    Group:Number:AVG humidity "Avg. Room Humidity [%.1f %%]" <temperature> (status)
    
    
    Group:Switch:OR(ON, OFF) lights "All Lights [(%d)]" <light> (All)
    
    Number tempChartPeriod          "Chart Period"
    Number tempSalon01 "Temperature [%s ยฐC]" <temperature> (temperature,humAndTemp)
    Number humSalon01 "Humidity [%s %%]" <temperature> (humidity,humAndTemp)
    Switch lightKitchenCabinet00	"Light 1" (lights, kcLights)
    Switch lightKitchenCabinet01	"Light 2" (lights, kcLights)
    Switch lightKitchenCabinet02	"Light 3" (lights, kcLights)
    Switch lightKitchenCabinet03	"Light 4" (lights, kcLights)
    
    Switch lightBar04		"Bar Lights" (lights, kLights, lrLights)
    
    Dimmer lightSalonCeiling00	"Light 1 [%s %%]" (lights, lrcLights)
    Dimmer lightSalonCeiling01	"Light 2 [%s %%]" (lights, lrcLights)
    Dimmer lightSalonCeiling02	"Light 3 [%s %%]" (lights, lrcLights)
    Dimmer lightSalonCeiling03	"Light 4 [%s %%]" (lights, lrcLights)
    Dimmer lightSalonCeiling04	"Light All [%s %%]" (lights,lrLights,allLights)
    Switch plugStrip01s12		"Sockets 1-2" <socket> (lrPlugStrip)
    Switch plugStrip01s34		"Sockets 3-4" <socket> (lrPlugStrip)
    
    String sensorLRCDimmer "Living Room Ceiling Light Sensor [%s]" (mysensors)
    String sensorLRStripPlug01 "Living Room Strip Plug 01 Sensor [%s]" (mysensors)
    String sensorLRHumTemp "Living Room Hum&Temp&Motion&Light  Sensor [%s]" (mysensors)
    String sensorKCLight "Kitchen&Bar Light Sensor [%s]" (mysensors)
    

    my test.sitemap

    sitemap demo label="Main Menu"
    {
    
    	Frame label="Home" {
    		Group label="Kitchen" icon="kitchen" {
    			Frame label="Kitchen" {
    				Group item=kLights label="Lights" {
    				Switch item=lightBar04 label="Bar Lights"
    				Switch item=kcLights label="Cabinet Lights"
    				Group item=kcLights 
    				}
    			}
    		}
    
    		Group item=livingRoom {
    			Frame label="Living Room" {
    				Group item=lrLights 
    				Group label="Sensors" icon="temperature" {
    					Text item=tempSalon01 valuecolor=[tempSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
    					Text item=humSalon01 valuecolor=[humSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
    					Switch item=tempChartPeriod label="Chart Period" mappings=[0="12 Hours", 1="Day", 2="Week", 3="Month"]
    					Chart item=humAndTemp period=12h refresh=5000 visibility=[tempChartPeriod==0,tempChartPeriod=="Uninitialized"]
    					Chart item=humAndTemp period=D refresh=1800 visibility=[tempChartPeriod==1]
    					Chart item=humAndTemp period=W refresh=3600 visibility=[tempChartPeriod==2]
    					Chart item=humAndTemp period=M refresh=7200 visibility=[tempChartPeriod==3]
    				}
    				Group item=lrPlugStrip
    			}
    		}
    		Group item=corridor 
    		Group item=bathroom icon="bath"
    		Group item=grandmotherRoom icon="smiley"
    	}
    
    	Frame label="Lights All"{
    		Switch item=lights mappings=[OFF="All Off"]
    		Group item=lights
    		Group item=mysensors
    	}
    

    hi all,

    does anyone have an arduino code for l154 nice work here above?
    i need an example only for arduino (dont have a rpi) on which i can connect a few relays and a few sensors like dht11 and a light sensor.
    Someone please a little help here with a arduino code or some links on where we can find something to work with this openhab configuration?
    thanks in advance.



  • one more question:
    to make the connection with openhab should i change this "String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }" to "String Arduino "Arduino" { serial="COM4" }" couse my arduino is connecting on com4?
    thanks!


  • Hero Member

    @ewgor said:

    String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }

    Use something like:

    String Arduino "Arduino" { serial="COM4@115200" }


  • @TimO said:

    @ewgor said:

    String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }

    Use something like:

    String Arduino "Arduino" { serial="COM4@115200" }
    

    thank you for answer TimO, i assume this 115200 is the baud rate, isn't it? on testing different arduino codes, i had to modify it to 9600 because otherwise it wouldn't work...
    can you please share with us any arduino code for a few relays and some sensors? or to suggest us some links where we can find something useful?
    i need an example only for an arduino (mega) connected directly through usb to my laptop.
    thanks again, i will try this "String Arduino "Arduino" { serial="COM4@115200" }" when i'll have an arduino code as an example.


  • Hero Member

    Yes, you're right, 115000 is the baudrate.

    Have you seen my tutorial?

    http://forum.mysensors.org/topic/1194/tutorial-openhab-with-serial-gateway
    tutorial-openhab-with-serial-gateway



  • I saw your tutorial but in there you speak about tests made on a system with Linux like a rpi and I'm working only for tests from my laptop with windows 7 and arduino mega! Later when I will have something working I'll purchase a rpi for a permanent installation but for the moment I need just the arduino code to match with this openhab configuration.
    Any idea?
    Thanks again.


  • Hero Member

    I'm using the standard serial gateway: http://www.mysensors.org/build/serial_gateway
    (For the mega you have to change CE/CSN Pin, just search the forum)

    The OpenHAB part of my tutorial will work on Windows 7 too, there's no difference in the OpenHAB configuration except the COM4 port you already mentioned.

    The arduino code you're searching is the MySensors standard stuff, there is no need to change that to make it work with OpenHAB.



  • @TimO i am trying to make this serial communication work following your tutorial. i don understand why it has to be so difficult for some of us who have small ideas about arduino i mean is not like today a bought it and i don't know a thing about it!
    cause was not working with my existing openhab i deleted all and i followed your link here https://openhab.ci.cloudbees.com/job/openHAB/ and i got this"distribution-1.7.0-SNAPSHOT-addons.zip" and this "distribution-1.7.0-SNAPSHOT-runtime.zip".
    now, do i need all addons or a few of them? if i need a few, which one? its not clear ...
    regarding arduino, i got all libraries from here http://www.mysensors.org/download/ and extrated into the libraries folder of arduino.
    when i compile the example sketch SerialGateway, it is compiling and i even can upload it but, starting the server with start.bat or start.sh and having the com4 modified and all items, rules and map according to your instruction, it doesnt work, i get this error "Error opening serial port 'COM4'.
    i dont know what to do! and i don't understand how to see the temp and humid. real values when you have uploaded a standard serial gateway and you don't have any commands in the arduino code about dht or other type of sensor! is this code only for test? just to see that you have the communication working and on the web it will appear just some values?
    its becoming really frustrating trying days and nights to make it work,, reading a lot of comments where other guys made it and you don't!
    can u please help? where i'm wrong? i'm using this time an arduino uno but this doesn't matter, i changet the string with baudrate115200, 9600, without it and nothing! i cant make the serial communication work!



  • @TimO hi here too,

    cant test this version because i get this error regarding DHT:
    Arduino: 1.5.8 (Windows 7), Board: "Arduino Uno"

    RelayActuator.ino:21:5: error: no matching function for call to 'DHT::DHT()'
    RelayActuator.ino:21:5: note: candidates are:
    In file included from RelayActuator.ino:6:0:
    D:\Kit\Arduino\libraries\DHT/DHT.h:40:4: note: DHT::DHT(uint8_t, uint8_t, uint8_t)
    DHT(uint8_t pin, uint8_t type, uint8_t count=6);
    ^
    D:\Kit\Arduino\libraries\DHT/DHT.h:40:4: note: candidate expects 3 arguments, 0 provided
    D:\Kit\Arduino\libraries\DHT/DHT.h:38:7: note: DHT::DHT(const DHT&)
    class DHT {
    ^
    D:\Kit\Arduino\libraries\DHT/DHT.h:38:7: note: candidate expects 1 argument, 0 provided
    RelayActuator.ino: In function 'void setup()':
    RelayActuator.ino:48:7: error: 'class DHT' has no member named 'setup'
    RelayActuator.ino: In function 'void updateHumidityTemp()':
    RelayActuator.ino:72:26: error: 'class DHT' has no member named 'getHumidity'
    RelayActuator.ino:84:27: error: 'class DHT' has no member named 'getTemperature'
    RelayActuator.ino:90:25: error: 'class DHT' has no member named 'toFahrenheit'
    Error compiling.

    This report would have more information with
    "Show verbose output during compilation"
    enabled in File > Preferences.
    i have downloaded all needed libraries from here http://www.mysensors.org/download/ but cant compile!
    do i need ther DHT library?
    thanks!


  • Hero Member

    @ewgor Hi!

    Using OpenHAB (1.X) with MySensors is a long and at the beginning frustrating process as OpenHAB itself don't support MySensors out of the box. I hope I'm able to change that with OpenHAB 2.0.

    1. OpenHAB 1.7.0 is stable. You don't have to use the snapshot release. But that won't solve your problems.

    2. You just need the serial binding from the addons. Copy "org.openhab.binding.serial-1.7.0-SNAPSHOT.jar" to "OPENHAB-HOME/addons". But I suppose you already did that, because of the error "Error opening serial port 'COM4'.

    3. https://github.com/openhab/openhab/wiki/Serial-Binding according to this "COM4@115200" should work fine. I've not tested it with windows yes. This is your main problem. Don't try to go further, nothing will work. Are you able to open the serial monitor in the Arduino Development Environment? With the correct baudrate you should see something like "Gateway startup complete".

    4. You're Arduino Development Environment can't find the libraries. I've extracted all libraries to "C:\Users\myUser\Documents\Arduino\libraries". It now looks like:

    
    Adafruit_BMP085
    BH1750
    Bounce2
    ...
    DHT
    ...
    MySensors
    ...
    

    The DHT library is part of the file you downloaded.



  • @TimO thanks for reply,

    1. first shot was with Openhab 1.7.0 from here http://www.openhab.org/downloads.html and than i followed your link from here https://openhab.ci.cloudbees.com/job/openHAB/ and tried with the SNAPSHOT 1.8.0 version, both of them works and i can test different examples from here with my laptop and 2 smartphones.
    2. every time i try a server, i have 2 folders with as follows: 1 folder is the original addons folder wich is empty and another one as a copy like addons1 in which i extracted all addons. Before starting the server i copy the needed addon (.jar file) in the original folder named addons, in my case the serial.jar.
    3. if the server is not started i can compile the SerialGateway code and i can upload it too into my arduino. The problem si that when i open the serial monitor of arduino IDE i get some strange chars like: \รš or LรŠ or Lล“ and this is happening every time i open the serial monitor. I think is a baudrate problem but i cant see where in the SerialGateway sketch i can change this baudrate or should i change it directly in the library? By the way, can you please tell me, why its not working with different baudrates?
    4. i have all libraries from here http://www.mysensors.org/download/ copied and pasted directly in my arduino libraries folder which in my case is in D/kit/arduino/libraries. For DHT i have DHT library / DHT tester! Do i need other library? i Know i tested a sketch for DHT11 and an LCD and it worked.

    However, if i have the server started on my laptop its impossible to compile the SerialGateway sketch and i receive this error posted above. I even can't upload the sketch if i close the server, i need to restart my PC....

    Maybe it would be a beeter sollution to use Mqtt because i have a wiznet w5100 and a ENC28J60 ethernet module but the problem is (i asked somewhere here on the forum) that i cannot use or test Mosquitto broker, and so i cannot test a Mqtt connection. I downloaded the broker from the original page for my system, i have it installed on windows but i cannot access any of the .exe files because of some missing dll. After days of searching and a lot of struggling i got the dll's but didn't start because of some unexpected error! I know this is the subject of another topic but i didn't get a reply there so i ask here...
    If i cannot test a server on my machine how to purchase a RPI and moreover i never had a RPI so you can imagine how many problems i will face. Anyhow, this is my intention, to buy a RPI and to have a permanent installation.
    Don't know what to do .... :(((


  • Hero Member

    Ok, I think we're getting closer.
    So, If you see strange chars in the serial monitor the baud rate of the serial monitor isn't right. Just change the baud rate in the serial monitor, it's a dropdown at the bottom right. If you set it to 115200 baud it should work (Gateway startup complete).

    The 115.200 is a fixed baud rate MySensors uses. It is faster than 9600 and the serial communication could be the bottleneck. In the MySensors library it is defined in MySensors.h. You may change that, but that won't help.

    I suppose you have a blocking issue, since both Arduino IDE and OpenHAB try to use the COM port. Try to make sure only one application at a time is running and using the port. At least OpenHAB should throw an error that the COM port is blocked. I'm not sure how Windows handles blocking.

    If you see "Gateway startup complete" in the Arduino IDE / serial monitor, close the Arduino IDE (and the serial monitor) and fire up OpenHAB with debugging enabled (start_debug.bat). Post everything the serial binding throws out here.

    Can't help you with MQTT because I haven't used it yet.



  • I changed the baud rate to 115200 and now it says "0;0;3;0;9;check wires" on both Arduino (Uno and Mega). I think i saw a topic here somewhere, do i need to change some pins in the SerialGateway sketch?


  • Hero Member

    Check the connections between NRF24L01+ and Arduino Uno.

    In case of the Arduino Mega you have to change the sketch (CE/CSN Pin), just search the forum for an example.



  • I dont have any NRF24L01 in myhouse! what is this device? do i have to buy one to see this SerialGateway working between my PC and my Arduino board?
    For my Mega ive searched on the the forum but i dont understand how to change the CE/CSN pin ...
    I asked on some other topic but no answer.


  • Admin

    @ewgor

    Have you read this page ?

    and this one.

    NRF24L01 is the essentially the heart of the mysensors system, it's the radio which it's build uppon.



  • @tbowmo yes i did, only is just i didnt understand that the NRF24L01 is a must! I already ordered a piece and in a few days i'll be able to test either the Serial Gateway or the Ethernet Gateway....



  • This post is deleted!


  • i solved the problem with DHT, now i need to know how to configure Openhab in order to see the the gateway. I changed the COM in items already.
    In order to test your sketch that one with DHT and 2 realys what should i do? do i need 2 arduinos: one as a gateway and 2nd as a node point? how many nRF modules do i need?
    Now i have nRF24L01 but i dont know how to make it work with OpenHAB
    In addons i have org.openhab.binding.serial-1.7.0.jar
    Any help please?
    Thanks.



  • Anyone, any idea how to test the serial gateway? At this point on the serial monitor i get 0;0;3;0;14;Gateway startup complete. How to test it with Openhab? PLS HELP ๐Ÿ™‚
    For gateway im using a UNO and i try to have my mega as a node point. If i use Arduino Mega as a gateway its ok, i couldnt find any connection scheme for the node point (mega or uno). Right now i see on the serial monitor of the node point check wires and on the gateway startup complete! Where is the problem? how to connect the node point with my relays and what should i see on the serial monitor? Again somebody pls help me understand how to test it with Openhab?


  • Hero Member

    For the Arduino Mega you have to change the connections. Check out this thread:

    http://forum.mysensors.org/topic/249/arduino-mega-sensor-shield-2

    When the "node point" starts up fine you should see a lot of messages coming on the serial monitor of the gateway. Then the communication between both nodes is working.



  • @TimO with your help again i managed to find the right pins on my mega and now with my dht11 connected i get the temp and hum values constantly. On the server side when i start the bat file or sh file i get the values on the node serial monitor but nothing apears on the localhost.
    there are any changes that needs to be done in the items, rules or the sitemap?
    thanks for replay.



  • today, trying to make it work i discovered that if i start the Openhab server i get the DHT11 values on the server and i can access the serial monitor of the node point but when i switch the arduino IDE to the serial gateway com4 i get this errors on the arduino IDE and i cannot acces the serial monitor:

    Arduino: 1.5.8 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
    
    processing.app.SerialException: Error opening serial port 'COM4'.
    
    	at processing.app.Serial.<init>(Serial.java:145)
    
    	at processing.app.Serial.<init>(Serial.java:90)
    
    	at processing.app.SerialMonitor.open(SerialMonitor.java:93)
    
    	at processing.app.Editor.handleSerial(Editor.java:2537)
    
    	at processing.app.EditorToolbar.mousePressed(EditorToolbar.java:357)
    
    	at java.awt.Component.processMouseEvent(Unknown Source)
    
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    
    	at java.awt.Component.processEvent(Unknown Source)
    
    	at java.awt.Container.processEvent(Unknown Source)
    
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    
    	at java.awt.Component.dispatchEvent(Unknown Source)
    
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    
    	at java.awt.Component.dispatchEvent(Unknown Source)
    
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    
    	at java.awt.EventQueue.access$200(Unknown Source)
    
    	at java.awt.EventQueue$3.run(Unknown Source)
    
    	at java.awt.EventQueue$3.run(Unknown Source)
    
    	at java.security.AccessController.doPrivileged(Native Method)
    
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    
    	at java.awt.EventQueue$4.run(Unknown Source)
    
    	at java.awt.EventQueue$4.run(Unknown Source)
    
    	at java.security.AccessController.doPrivileged(Native Method)
    
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    
    	at java.awt.EventDispatchThread.run(Unknown Source)
    
    Caused by: jssc.SerialPortException: Port name - COM4; Method name - openPort(); Exception type - Port busy.
    
    	at jssc.SerialPort.openPort(SerialPort.java:164)
    
    	at processing.app.Serial.<init>(Serial.java:141)
    
    	... 35 more
    
    Error opening serial port 'COM4'.
    
      This report would have more information with
      "Show verbose output during compilation"
      enabled in File > Preferences.
    
    

    On the serial monitor of the node point i receive this:

    repeater started, id 101
    send: 101-101-0-0 s=255,c=0,t=18,pt=0,l=5,st=ok:1.4.1
    send: 101-101-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    send: 101-101-0-0 s=255,c=3,t=11,pt=0,l=5,st=ok:Relay
    send: 101-101-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 101-101-0-0 s=1,c=0,t=3,pt=0,l=0,st=fail:
    send: 101-101-0-0 s=2,c=0,t=3,pt=0,l=0,st=ok:
    send: 101-101-0-0 s=0,c=0,t=7,pt=0,l=0,st=ok:
    send: 101-101-0-0 s=1,c=0,t=6,pt=0,l=0,st=ok:
    Failed reading humidity from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    Failed reading temperature from DHT
    send: 101-101-0-0 s=1,c=1,t=0,pt=7,l=5,st=ok:31.0
    T: 31.00
    send: 101-101-0-0 s=1,c=1,t=0,pt=7,l=5,st=fail:30.0
    T: 30.00
    send: 101-101-0-0 s=1,c=1,t=0,pt=7,l=5,st=ok:31.0
    T: 31.00
    
    

    and on the Openhab start.bat i see this:

    2015-07-15 17:48:14.153 [INFO ] [runtime.busevents             ] - Arduino state
     updated to 0;0;3;0;9;read: 101-101-0 s=255,c=3,t=11,pt=0,l=5:Relay
    101;255;3;0;11;Relay
    0;0;3;0;9;read: 101-101-0 s=255,c=3,t=12,pt=0,l=3:1.0
    101;255;3;0;12;1.0
    0;0;3;0;9;read: 101-101-0 s=1,c=0,t=3,pt=0,l=0:
    101;1;0;0;3;
    0;0;3;0;9;read: 101-101-0 s=2,c=0,t=3,pt=0,l=0:
    101;2;0;0;3;
    0;0;3;0;9;read: 101-101-0 s=0,c=0,t=7,pt=0,l=0:
    101;0;0;0;7;
    0;0;3;0;9;read: 101-101-0 s=1,c=0,t=6,pt=0,l=0:
    101;1;0;0;6;
    
    ArduinoUpdate -> 0;0;3;0;9;read: 101-101-0 s=255,c=3,t=11,pt=0,l=5:Relay
    101;255;3;0;11;Relay
    0;0;3;0;9;read: 101-101-0 s=255,c=3,t=12,pt=0,l=3:1.0
    101;255;3;0;12;1.0
    0;0;3;0;9;read: 101-101-0 s=1,c=0,t=3,pt=0,l=0:
    101;1;0;0;3;
    0;0;3;0;9;read: 101-101-0 s=2,c=0,t=3,pt=0,l=0:
    101;2;0;0;3;
    0;0;3;0;9;read: 101-101-0 s=0,c=0,t=7,pt=0,l=0:
    101;0;0;0;7;
    0;0;3;0;9;read: 101-101-0 s=1,c=0,t=6,pt=0,l=0:
    101;1;0;0;6;
    2015-07-15 17:48:15.171 [INFO ] [runtime.busevents             ] - Arduino state
     updated to 0;0;3;0;9;read: 101-101-0 s=1,c=1,t=0,pt=7,l=5:31.0
    101;1;1;0;0;31.0
    
    ArduinoUpdate -> 0;0;3;0;9;read: 101-101-0 s=1,c=1,t=0,pt=7,l=5:31.0
    101;1;1;0;0;31.0
    2015-07-15 17:48:44.203 [INFO ] [runtime.busevents             ] - Arduino state
     updated to 0;0;3;0;9;read: 101-101-0 s=0,c=1,t=1,pt=7,l=5:35.0
    101;0;1;0;1;35.0
    
    ArduinoUpdate -> 0;0;3;0;9;read: 101-101-0 s=0,c=1,t=1,pt=7,l=5:35.0
    101;0;1;0;1;35.0
    
    

    help ๐Ÿ™‚


  • Hero Member

    The access to the serial port is exclusive, stop OpenHAB to access the serial port of The gateway with the arduino IDE.



  • @TimO i saw that I can access the gateway and see what node point transmit but as you say without having the server start.
    How do I see temp and hum on the local host? And what do I need to do to switch the two LEDs from local host?
    As always, thanks for sharing a little part of your experience ๐Ÿ™‚


  • Hero Member

    Use something like this in the rules file:

    For a button (always sends on when activated):

    rule "Licht Flur EG"
            when
                    Item corridorLight01 received update
            then
                    sendCommand(Arduino, "102;1;1;0;2;1\n")
    

    For a switch use something like

    rule "Kรผche"
            when
                    Item kitchenLight01 received command
            then
                    if(receivedCommand==ON) {
                            sendCommand(Arduino, "102;1;1;0;2;1\n")
                    }
                    if(receivedCommand==OFF) {
                            sendCommand(Arduino, "102;1;1;0;2;0\n")
                    }
    
    end
    


  • So TimO you say your example above (arduinos sketches for the serial gateway and the 2nd one for temp, hum and two switches + openhab items, rules and sitemap) is not working? i just followed and nothing happen ... still strugling. Now you give me this example which has nothing to do with your example. If i want to use it i need to modify all files and i dont know how!
    Can anyone help me??


  • Hero Member

    Well, I thought your base is my tutorial: http://forum.mysensors.org/topic/1194/tutorial-openhab-with-serial-gateway

    The advantage of OpenHAB is, you're very free and are able to do things you like to do. The disadvantage is, you currently have to "program" your rules.

    It would help to know your OpenHAB configurations, sketches and so on, because I'm using my own OpenHAB (and MySensors) configuration/installation, that certainly is not the best configuration fรผr everyone.
    (But it works the way I want it to work ;-))

    You only asked for (and got) pieces of the puzzle, you have to put it together by yourself or ask for the complete solution, as you did in another thread. ๐Ÿ˜„



  • @TimO
    I see, so if are not a programmer and you don't know how to make your own sketches (arduino, rules) you don't have any chance to make your own project .... i thought, being open source and asking for help in a community where you can find a lot of guys who have idea about the subject, maybe you can make it easier without spending hours and hours just to come back to the same place you started , moreover without a solution.
    Anyhow, thanks a lot, with the help you gave i am almost there but i think i still need to wait maybe a half year till i'll see my project on ๐Ÿ˜ž



  • Hi,
    Can anyone help? I'm trying to move my server from my laptop to my raspberry pi 2 and I'm having problems.
    I changed the port in the items file with

    "String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }"
    

    And now the server receive the commands from my laptop or from my phone but it not sends the info to the node point and it not receive info from the node point too.
    If I start the server from my laptop with start.bat it works but when I start the server from my pi with
    Sudo /opt/openhab/start.sh it acts as I said above!
    Can anyone please help me understand what I'm missing?

    Thanks!


  • Hero Member

    Try to connect with a terminal software like miniterm to /dev/ttyUSB0 and check if data from the serial gateway is received.

    miniterm.py -b 115200 -p /dev/ttyUSB0
    

    You may have to install miniterm first.



  • @TimO i solved following your tutorial here with dmesg and checking for what usb name rpi have for the gateway. Still not did those steps for a permanent usb but its on going.
    Thanks!



  • @TimO Hi TimO! This is Fay from codebender.cc Thank you for using codebender! I just wanted to let you know that one of the sketches you are using in this comment has been deleted and so it is not available for users to view it. Let me know if you have any question. ๐Ÿ™‚


  • Hero Member

    @Fay-Candiliari : Thank you very much for the hint!


  • Admin

    @Fay-Candiliari

    Hi @Fay-Candiliari , Nice to see you here!



  • @TimO You are welcome ๐Ÿ™‚



  • Hi @hek Likewise! ๐Ÿ™‚



  • I'm having trouble with test.rules when two switches change its values really quickly one after the other. I can do that in a couple of tries via the web UI or the android UI. This is the output that looks odd:

    2016-01-05 19:39:54.405 [INFO ] [runtime.busevents             ] - relay01 received command ON
    2016-01-05 19:39:54.469 [INFO ] [runtime.busevents             ] - relay02 received command ON
    Function: switchOperation >> 1;1;1;1;2;1
    Function: switchOperation >> 1;2;1;1;2;1
    2016-01-05 19:39:54.772 [INFO ] [runtime.busevents             ] - Arduino received command 1;1;1;0;2;1
    
    2016-01-05 19:39:54.797 [INFO ] [runtime.busevents             ] - Arduino received command 1;2;1;0;2;1
    
    2016-01-05 19:39:55.033 [INFO ] [runtime.busevents             ] - relay01 received command ON
    2016-01-05 19:39:55.338 [INFO ] [runtime.busevents             ] - relay02 state updated to ON
    2016-01-05 19:39:55.398 [INFO ] [runtime.busevents             ] - relay02 state updated to ON
    Light Item: relay02 Light: ON
    Light Item: relay02 Light: ON
    

    As you can see, it starts fine but at the end it is talking about the same relay twice and I end up with just one relay on. It actually looks like an openhab issue but I'm not sure.

    Any help is appreciated.



  • I am having the same issue. When I start my sensor, it sends a lot of information seemingly at once. The rule gets confused and runs the rule multiple times on one serial command (rather than each individually).

    Notice below the "Arduino" item is getting updates frequently. Below that is my output in the rule to handle the update. Notice it prints multiple 105;0;0;0;7; in place of the other inputs (105;255;3;0;15; for example)

    
    2016-01-26 16:15:36.414 [INFO ] [runtime.busevents             ] - Arduino state updated to 105;255;3;0;15;
    2016-01-26 16:15:36.418 [INFO ] [runtime.busevents             ] - Arduino state updated to 105;255;0;0;17;2.0.0-beta
    2016-01-26 16:15:36.425 [INFO ] [runtime.busevents             ] - Arduino state updated to 105;255;3;0;6;0
    2016-01-26 16:15:36.429 [INFO ] [runtime.busevents             ] - Arduino state updated to 105;255;3;0;11;Garage Sensor
    2016-01-26 16:15:36.433 [INFO ] [runtime.busevents             ] - Arduino state updated to 105;255;3;0;12;1.0
    2016-01-26 16:15:36.438 [INFO ] [runtime.busevents             ] - Arduino state updated to 105;0;0;0;7;
    2016-01-26 16:15:36.557 [INFO ] [runtime.busevents             ] - Arduino state updated to 105;1;1;0;0;68.0
    2016-01-26 16:15:37.058 [INFO ] [runtime.busevents             ] - Arduino state updated to 105;0;1;0;1;36.0
    
    105;0;0;0;7;
    105;0;0;0;7;
    105;0;0;0;7;
    105;0;0;0;7;
    105;1;1;0;0;68.0
    105;0;1;0;1;36.0
    105;0;0;0;7;
    105;0;0;0;7;
    


  • @knoid
    Found out that you can use locks in the rules to prevent uncertainty with the "Arduino" variable caused from multiple instances of the rule running simultaneously.
    Example:

    import java.util.concurrent.locks.ReentrantLock
    
    var java.util.concurrent.locks.ReentrantLock lock  = new java.util.concurrent.locks.ReentrantLock()
    
        rule "Arduino sends to Openhab"
        when
            Item Arduino received update
        then
            lock.lock()
            try {
                // do stuff (e.g. create and start a timer ...)
            } finally{
               lock.unlock()
            }
        end
    

  • Hero Member

    Cool! Thanks for sharing!



  • I know... it's an old thread. And i know openHAB2 is there. But it's still Alpha and i am beginner. Maybe not a good idea ๐Ÿ˜‰

    Somehow my sensors will not bind. I downloaded and installed all fresh.
    When i start openHAB with sudo it loads normal but nodes never connected to openHAB ๐Ÿ˜ž

    EDIT:
    I just made a new install combined the infos from these instructions and that worked for me:
    https://github.com/openhab/openhab/wiki/Linux-and-OS-X#apt-get
    http://www.makeuseof.com/tag/getting-started-openhab-home-automation-raspberry-pi/

    Thx for your answer Tim0 and sorry for posting in wrong thread


  • Hero Member

    Hey @edsteve !

    This thread mainly covers the serial connection via the serial binding and by using rules.

    You are using the binding for OH1, so I suggest to start a new thread or trigger @bkl. ๐Ÿ™‚


Log in to reply
 

Suggested Topics

  • 22
  • 135
  • 132
  • 5
  • 2
  • 1

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts