Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Daniel Lindberg
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Daniel Lindberg

    @Daniel Lindberg

    0
    Reputation
    16
    Posts
    687
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Daniel Lindberg Follow

    Best posts made by Daniel Lindberg

    This user hasn't posted anything yet.

    Latest posts made by Daniel Lindberg

    • RE: Openhab - How to respond to Arduino request?

      I did, but after a simulated "power outage" item.state would simply return 0, so my sensor would reset and start accumulating KWH from 0 again.

      I updated use rrd4j rather than my.openhab and used

      pulseCountItem.previousState(false, "rrd4j").state // get the most recent update, even if it is the same as the current state
      

      It's now working 🙂

      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • RE: Openhab - How to respond to Arduino request?

      @TimO I did, and I can see my stored values in the "my openhab" console.

      I cross-posted my issue on open-habs community, and the concensus there seems to be that my openhab does not support restore/retrieve queries.

      https://community.openhab.org/t/unable-to-restore-state-for-item/3172/2

      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • RE: Openhab - How to respond to Arduino request?

      @TimO said:

      @Daniel-Lindberg : I suppose you are already storing the pulse count in an item?
      If this is the case you simple replace "0" with "pulseCountItem.state".

      For example:

      if(msgType == 2){
          if (subType == V_VAR1){
              sendCommand(Arduino,"105;1;1;0;24;" + pulseCountItem.state + "\n")
          }
      }
      

      Where pulseCountItem is the name of the item you specified in the item definition file.

      @TimO , I tried this command earlier today, but I'm seeing the following statement in the log:

      given new state is NULL, couldn't post update for 'pulseCountItem'
      

      So it seems like there is no state for the item.
      Also tried using

      pulseCountItem.previousState(now).state
      

      but that gives

      Error during the execution of rule 'Arduino sends to Openhab': Could not invoke method: org.openhab.core.persistence.extensions.PersistenceExtensions.previousState(org.openhab.core.items.Item,boolean,java.lang.String) on instance: null
      

      Any ideas on how to proceed?

      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • RE: Openhab - How to respond to Arduino request?

      @TimO No, Just one power meter. My current items hashmap is

      // 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;"
      )
      

      Not sure how to separate the numbers for watts, kwhs and pulse counts since they all share the same CHILD_ID (in the example files). Should I change that to be three separate child IDs ?

      MyMessage wattMsg(CHILD_ID_1,V_WATT);
      MyMessage kwhMsg(CHILD_ID_2,V_KWH);
      MyMessage pcMsg(CHILD_ID_3,V_VAR1);
      

      It feels like using the same CHILD_ID for all three messages would cause postUpdate to write watts, kwhs and pc to the same item, which wouldn't make sense right?

      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • RE: Openhab - How to respond to Arduino request?

      Actually no, not yet. I have been to obsessed with getting a response back to my sensor 🙂
      Next step would be to store the value, and send the last one back as per your example.

      One thing I still don't understand. Do I need a separate item for storing the pulse count?
      Perhaps I actually need three items, since in my sensor code (basically copy/paste from mysensors example) I have. Do I generally need one openhab item per message ?

      MyMessage wattMsg(CHILD_ID,V_WATT);
      MyMessage kwhMsg(CHILD_ID,V_KWH);
      MyMessage pcMsg(CHILD_ID,V_VAR1);
      
      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • RE: Openhab - How to respond to Arduino request?

      Eventually this is what worked for me:

      if(msgType == 2){
          if (subType == V_VAR1){
              sendCommand(Arduino,"105;1;1;0;24;0\n")
          }
      }
      

      Just an example of course. Here I'm saying that the last pulse count is always zero. But this will return data to my sensor at least.

      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • RE: Openhab - How to respond to Arduino request?

      This is the output from the serial monitor when starting the sensor:

      sensor started, id=105, parent=0, distance=1
      send: 105-105-0-0 s=255,c=3,t=11,pt=0,l=12,sg=0,st=ok:Energy Meter
      send: 105-105-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.0
      send: 105-105-0-0 s=1,c=0,t=13,pt=0,l=0,sg=0,st=ok:
      send: 105-105-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
      send: 105-105-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
      

      I'm not storing any pulse count yet, still trying to figure out how everything works together.

      My rules, still based on your code, where I've just added another if for now to log the request

      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 )
                          }
                      }    
                  // Message Request
                  if(msgType == 2){
                  	logInfo("TestCheck", "Request, SubType: " + subType)
                   
                  }
      
      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • Openhab - How to respond to Arduino request?

      In the EnergyPulseMeter example that comes with MySensors, we have this line

      gw.begin(incomingMessage);
      

      The incomingMessage method is then defined as:

      void incomingMessage(const MyMessage &message) {
        if (message.type==V_VAR1) {  
          pulseCount = oldPulseCount = message.getLong();
          Serial.print("Received last pulse count from gw:");
          Serial.println(pulseCount);
          pcReceived = true;
        }
      }
      
      

      We also have

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

      So if my understanding is correct, the last call is a request to the GW, and whenever we get a response, the incomingMessage method will handle it.

      My question then - How can I respond to this request from my Openhab rules?

      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • RE: Openhab issue: Error during the execution of rule 'Arduino sends to Openhab': 5

      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

      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg
    • 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?

      posted in Troubleshooting
      Daniel Lindberg
      Daniel Lindberg