Navigation

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

    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
    • RE: [Tutorial] openHAB with serial gateway

      Eventually solved it by just omitting SerialNumber, i.e.

      SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{serial}=="3f980000.usb", SYMLINK+="ttyUSB99
      

      I guess that could cause problems if I would attached more similar devices to my RPI, but I don't know if there is any point in having more than one gateway? (unless you have > 255 sensors I guess)

      posted in OpenHAB
      Daniel Lindberg
      Daniel Lindberg
    • RE: [Tutorial] openHAB with serial gateway

      I'm having issues getting the ttyUSB99 fix to work.
      I'm running openhab 1.7.1 and it was installed using apt-get.
      My dmseg output looks like this

      [10167.765598] usb 1-1.2: USB disconnect, device number 4
      [10167.766311] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
      [10167.766407] ch341 1-1.2:1.0: device disconnected
      [10171.843803] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
      [10171.946998] usb 1-1.2: New USB device found, idVendor=1a86, idProduct=7523
      [10171.947025] usb 1-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
      [10171.947042] usb 1-1.2: Product: USB2.0-Serial
      [10171.948288] ch341 1-1.2:1.0: ch341-uart converter detected
      [10171.952514] usb 1-1.2: ch341-uart converter now attached to ttyUSB0
      

      As you can see there is no SerialNumber here, but I found it using

      pi@raspberrypi ~ $ udevadm info -a -n /dev/ttyUSB0 | grep '{serial}' | head -n1
          ATTRS{serial}=="3f980000.usb
      

      So I created a rules file looking like this:

      pi@raspberrypi ~ $ cat /etc/udev/rules.d/99-usb-serial.rules
      SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{serial}=="3f980000.usb", SYMLINK+="ttyUSB99"
      

      I have disconnected and reconnected my gateway.
      But starting openhab now just results in the following error:

      2015-09-20 09:24:48.867 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type 'serial' of item ?Arduino? could not be parsed correctly.
      org.openhab.model.item.binding.BindingConfigParseException: Could not open serial port /dev/ttyUSB99: Serial port '/dev/ttyUSB99' could not be found. Available ports are:
      /dev/ttyUSB0
      

      What can I do to resolve this?

      posted in OpenHAB
      Daniel Lindberg
      Daniel Lindberg
    • RE: Is this enough to get me started?

      Oh well, I placed my order yesterday evening. Have a friend who can help with soldering. Bought some mini pro 3v3, which should be enough to power the dht22?

      posted in My Project
      Daniel Lindberg
      Daniel Lindberg
    • RE: Is this enough to get me started?

      Looking at the shop, the battery holders have the description .
      "3V AA Battery holder
      For powering 3.3V Arduino. Requires a step-up converter"
      The only step up converter I find in the shop says

      "DC-DC Step Up Boost Module
      Input 1-3V , 5V Output. Use this if you need to power 5V sensors from a 3.3V Arduino Pro Mini". Is this what I need for the battery holder? (it doesnt sound like it, but it's all I can find)

      EDIT: Perhaps this is what I need? http://www.aliexpress.com/item/8-pcs-Ultra-small-DC-DC-0-8-3-3V-to-DC-3-3V-Step-UP/32268496143.html

      posted in My Project
      Daniel Lindberg
      Daniel Lindberg
    • RE: Is this enough to get me started?

      @Dwalt said:

      @Daniel-Lindberg If you go with the Sensebender, you will have to solder on the radio and power.

      Oh... I don't wanna go there. So what would I replace the sensebenders with, given I need a humidity/temp sensor and battery power? Arduino Pro Mini 3,3V and a DHT11/22? Do I need an step up/down regulator as well?

      posted in My Project
      Daniel Lindberg
      Daniel Lindberg
    • Is this enough to get me started?

      So I've never ever been much into electronics before, however I do have a fair amount of programming experience. I've been looking to buy a couple of humidity sensors for my house, that is until I stumpled upon this site and started reading. Now I realize that I can probably build them myself, and have some fun while doing so 🙂

      I've read all the getting started guides and watched a couple of videos, however I'm still not really sure exactly what I need to buy to build my sensors. As my first project I would like to build 2 battery powered humidity/temp sensors.

      This is what I think I need:

      For the sensors

      • 2x Sensebender Micro (seems like a good fit with build in temp/humidity sensors)
      • 2x NRF24L01 (Looks like minimum to buy is 10?)
      • 2x 3V AA Battery holder
      • 1x FTDI USB to TTL Serial Adapter

      Gateway (based on petewill's video)

      • 1x Arduino Nano Compatible
      • 1x NRF24L01
      • 1x 4.7 uf capacitor

      Controller

      • 1x Rasberry PI 2, probably with OpenHab

      I guess I need some cables as well (no idea how to solder...)
      Female - Female Dupont jumper cables.

      Can someone please tell me if this is it, or did am I missing something in my list?
      Also, is Rasberry PI 2 with OpenHab a reasonable choice?

      posted in My Project
      Daniel Lindberg
      Daniel Lindberg