Serial Gateway connection to Openhab


  • 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
  • 3
  • 10
  • 2
  • 5
  • 132

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts