Sending serial commands to sensors

  • I'm having trouble sending serial commands from openhab to my sensor nodes. The first thing I'm attempting is to change the units on the my sensors humidity sketch from Celsius to Fahrenheit. I wrote a crude rule that seemed to be successfully sent to the arduino, but I saw nothing on the serial monitor of the arduino sensor and saw no changes in the temperatures reported. How can I further troubleshoot this?

  • I'm making slow progress on this however I'm still running into a wall. I have the following rule setup:

    rule "Test Rule"
    		Item Units received update
    		var String status
    		if(Units.state == ON)
    			status = "I"
    			status = "M"
    		sendCommand(Arduino, "101;255;3;0;6;" + status + "\n")
    		println("Updated Sensor Units to " + status +)

    I'm attempting to tell the serial monitor to report the temperature in imperial units (Fahrenheit) as opposed to the default metric units (Celsius). The rule seems to be running successfully, but I'm getting the following error:

    2015-05-12 16:57:52.733 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Test Rule': Index: 1, Size: 1

    I can't seem to find any reference to this error. I don't see anything on the serial monitor of the arduino nano after flipping the switch on my sitemap when using the humidity sketch from the mysensors main site.

  • This post is deleted!

  • Did you figure this out? I am trying to do the same thing.

  • In the println part there is a string missing at the end after the +, isn't it?

  • @Jan-Gatzke I'm not sure that I understand what you mean. Maybe you're referring to the + after status? If so, I think you may be right, but I would assume that will only affect what is printed in the console, and not what is sent to the remote sensor. In the example above, I believe that 101;255;3;0;6;I\n would be sent if the switch was on, and 101;255;3;0;6;M\n would be sent if the switch was off.

    I believe that most of my problem is trying to figure out what should be sent to the remote sensor to enable this. In the above case, my remote sensor is ID 101. Ideally, I'd like to send the message to all sensors, and not just a certain node ID. Would that be 255;255;3;0;6;I\n?

    At one point, I thought I had this working, but it wasn't repeatable.

  • @Tango2

    I don't think there is a broadcast function in mysensors. You have to call the nodes one by one. I probably found another mistake in your rule. The rule has to be ended with "end". Is this missing or just not copied? The rest looks good. I have similar rules working. Can't say much to the format of the command, because I've never switched the units for y temp sensors.

  • Also, something to remember with your test example, is that the isMetric function is only called in the setup portion of the standard code, in other words when the arduino is first started. So if you are going to swap the functions on the fly then you would need to modify the standard code.

    If you have been restarting the arduino's to check then I apologise in advance! Just something that occurred to me on reading your issues.

  • @Chester good point, but I was restarting the arduino and still couldn't get this to work correctly. Also, the missing "end" was just missed out of the paste here, it was in my code.

Suggested Topics