Openhab issue: Error during the execution of rule 'Arduino sends to Openhab': 5



  • So I've managed to build my gateway and connect it to my RPI running Openhab 1.7.1. I'm now trying to connect my pulse power sensor to the gateway (http://www.mysensors.org/build/pulse_power). I've been following this guide http://forum.mysensors.org/topic/1194/tutorial-openhab-with-serial-gateway, but I'm receiving a very non-specifc error from Openhab. The error message is simply "5". I've enabled debug-logging, but it's now much help.

    2015-09-20 16:35:27.063 [DEBUG] [.o.m.c.i.folder.FolderObserver] - Refreshing folder 'sitemaps'
    2015-09-20 16:35:27.065 [DEBUG] [.o.m.c.i.folder.FolderObserver] - Refreshing folder 'persistence'
    2015-09-20 16:35:27.070 [DEBUG] [.o.m.c.i.folder.FolderObserver] - Refreshing folder 'rules'
    2015-09-20 16:35:27.073 [DEBUG] [.o.m.c.i.folder.FolderObserver] - Refreshing folder 'scripts'
    2015-09-20 16:35:27.076 [DEBUG] [.o.m.c.i.folder.FolderObserver] - Refreshing folder 'items'
    2015-09-20 16:35:34.456 [DEBUG] [b.serial.internal.SerialDevice] - Received message '0;0;3;0;9;read: 255-255-0 s=255,c=3,t=3,pt=0,l=0,sg=0:
    255;255;3;0;3;
    ' on serial port /dev/ttyUSB99
    2015-09-20 16:35:34.460 [DEBUG] [m.r.internal.engine.RuleEngine] - Executing rule 'Arduino sends to Openhab'
    2015-09-20 16:35:34.585 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Arduino sends to Openhab': 5
    

    My rules file (basically copy/paste from tutorial, and added my node_id 105 to the hash map):

    import org.openhab.core.library.types.*
    import org.openhab.core.persistence.*
    import org.openhab.model.script.actions.*
    import org.joda.time.*
    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(
        "101;0;"            -> "livingHum01",
        "livingHum01"       -> "101;0;",
        "101;1;"            -> "livingTemp01",
        "livingTemp01"      -> "101;1;",
        "105;1;"            -> "cellarPow01",
        "cellarPow01"       -> "105;1;"
    )
    
    
    //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 )
                        }
                    }
                // 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
    

    What can I do to get more info about this error?



  • I have not checked your code. But opening "{" and closing "}" brackets should have the same count.


  • Hero Member

    I've lately had a similar problem, where the error log didn't help and changed my rules a little.

    Could you test the modifications?

    import org.openhab.core.library.types.*
    import org.openhab.core.persistence.*
    import org.openhab.model.script.actions.*
    import org.joda.time.*
    import java.util.*
    import org.eclipse.xtext.xbase.lib.*
    import org.openhab.core.items.*
    import org.openhab.core.library.types.*
    import org.openhab.core.library.types.PercentType
    import org.openhab.core.library.items.SwitchItem
    
    
    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(
        "101;0;" 				-> "bathHum01",
        "bathHum01" 			-> "101;0;",
        "101;1;" 				-> "bathTemp01",
        "bathTemp01" 			-> "101;1;",
        "101;2;" 				-> "bathVolt01",
        "bathLastUpdate01" 			-> "101;99;",
        "101;99;"				-> "bathLastUpdate01",
        "bathVolt01" 			-> "101;2;",
        "102;99;"				-> "basementLastUpdate01",
        "basementLastUpdate02" 		-> "102;99;",
        "102;1;"				-> "corridorSwitch01",
        "corridorSwitch01" 			-> "102;1;",
        "102;2;"				-> "corridorSwitch02",
        "corridorSwitch02"			-> "102;2;",
        "103;99;"				-> "livingLastUpdate01",
        "livingLastUpdate01"		-> "103;99;",
        "103;0;" 				-> "livingHum01", 
        "livingHum01" 			-> "103;0;",
        "103;1;" 				-> "livingTemp01", 
        "livingTemp01" 			-> "103;1;",
        "103;2;" 				-> "livingVolt01", 
        "livingVolt01" 			-> "103;2;",
        "103;3;" 				-> "livingWindow01", 
        "livingWindow01" 			-> "103;3;",
        "workTemp01"			-> "104;1;",
        "104;1;"				-> "workTemp01",
        "workHum01"				-> "104;2;",
        "104;2;"				-> "workHum01",
        "workVolt01"			-> "104;199;",
        "104;199;"				-> "workVolt01",
        "workLastUpdate01"			-> "104;99;",
        "104;99;"				-> "workLastUpdate01",
        "kitchenTemp01"                     -> "105;1;",
        "105;1;"                            -> "kitchenTemp01",
        "kitchenHum01"                      -> "105;2;",
        "105;2;"                            -> "kitchenHum01",
        "kitchenLastUpdate01"		-> "105;99;",
        "105;99;"				-> "kitchenLastUpdate01",
        "kitchenVolt01"			-> "105;199;",
        "105;199;"				-> "kitchenVolt01",
        "childrenHum01"			-> "106;0;",
        "106;0;"				-> "childrenHum01",
        "childrenTemp01"			-> "106;1;",
        "106;1;"				-> "childrenTemp01",
        "childenPresenceSim01"		-> "106;3;",
        "106;3;"				-> "childrenPresenceSim01",
        "childrenLastUpdate01"		-> "106;99;",
        "106;99;"				-> "childrenLastUpdate01"			
    )
    
    //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) {
                println("#### LINE : " + line)
                if(line != "") { 
    	            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))
    	            if(message.size == 6) {
    	            	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_VOLTAGE){
    		                    postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    		                    println ("Voltage item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " volt: " + msg )
    		                    }
    		                if (subType == V_TRIPPED){
    		                    println ("Window item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " status: " + Integer::parseInt(msg) )
    		                    if(Integer::parseInt(msg) == 1) {
    					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), "OPEN")                    } 
    		                    if(Integer::parseInt(msg) == 0) {
    		                    	postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), "CLOSED")
    		                    } 
    		                }
            	        	var String dateTimeNow = callScript("dateTimeNow")
    		                postUpdate(sensorToItemsMap.get(nodeId + ";99;"), dateTimeNow)    
            		    // 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
    


  • I found late last night that the issue was the line

    var String msg = message.get(5)
    

    so by looking at your code I'm pretty confident that it will work.

    I haven't digged into the details, but it seems like the Pulse Meter request for last pulse count

    // Fetch last known pulse count value from gw
    gw.request(CHILD_ID, V_VAR1);
    
    

    doesn't carry any payload, so String[] message has a length of 5 rather than 6. So the error message "5" is some weird presentation of an IndexOutOfBoundsException


Log in to reply
 

Suggested Topics

2
Online

11.4k
Users

11.1k
Topics

112.7k
Posts