Using dashing with Openhab2

hi,
question is related Openhab and Dashing.
the problem is, how to define the OH-rules, in order to push the data to Dashing:

the code for the openhab-rule from:

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 java.util.concurrent.locks.*

var Map lastStateMap = new HashMap()
var Lock lock = new ReentrantLock()

rule "Post changes to Dashing Dashboard"
when
Item gDashboard received update
then
lock.lock()
//logInfo(“Dashboard”,“Dashing group rule triggered.”)
gDashboard?.members.forEach[t |
var lastState = lastStateMap.put(t.name, t.state)
if (lastState != t.state || lastState == null) {

                            val DASHING_TOKEN = '"auth_token" : "YOUR_AUTH_TOKEN"'
                            val DASHING_URI = "http://localhost:3030/widgets/"
                            ///logInfo("Dashboard","Item " + item.name + " changed.")
                            logInfo("Dashboard","Item " + t.name + " has changed state from " +lastState.toString + " to: " + t.state.toString)
                            var uri = DASHING_URI + t.name
                            var json = '{' + DASHING_TOKEN + ', '
                            if (t.state.toString.startsWith("{")){
                                    var internalJSON = t.state.toString.substring(1) //remove opening '{' as the string will be concatenated with our prefix items
                                    //internalJSON = internalJSON.substring(0,internalJSON.length() - 1)
                                    json = json +  t.state.toString.substring(1)
                                    logInfo ("Dashboard","[Debug] json = " + json)
                            } else{
                                    json = json + ' "state" : "' + t.state.toString + '"}'
                            }
                            logInfo ("Dashboard", "POSTING: " + json)
                            logInfo ("Dashboard", "URI: " + uri + "; JSON = " + json )
                            sendHttpPostRequest(uri, "HTTP.CONTENT_TYPE_JSON", json)
                    }
           ]
    lock.unlock()

end

in Openhab2 (latest snap) i get this error:
2016-02-25 19:43:54.142 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Post changes to Dashing Dashboard': Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null

in Openhab1 it is working.(same file)
2016-02-25 20:28:00.012 [INFO ] [openhab.model.script.Dashboard] - Item Temperature_FF_Office has changed state from 17.60000000 to: 19.00000000 2016-02-25 20:28:00.016 [INFO ] [openhab.model.script.Dashboard] - POSTING: {"auth_token" : "YOUR_AUTH_TOKEN", "value" : "19.00000000"} 2016-02-25 20:28:00.017 [INFO ] [runtime.busevents ] - Temperature_FF_Bed state updated to 17.90000000 2016-02-25 20:28:00.016 [INFO ] [openhab.model.script.Dashboard] - URI: http://localhost:3030/widgets/Temperature_FF_Office; JSON = {"auth_token" : "YOUR_AUTH_TOKEN", "value" : "19.00000000"}


what is the issue, why in OH2 it is not working, but in OH1 it is OK?
is there any better way to post the data to dashing?

thanks, Martin

The problem seems to be in how the sendHttpPostRequest action works in OH2. You can try putting quotations around json string. This will get rid of the exception. However, for some reason I am not seeing the post reaching Dashing using sendHttpPostRequest. For now, I’ve reverted back to executeCommand and using curl.

This is not ideal (it requires curl to be installed) and I will look further into it when I get time, and will post updates to my main thread (https://community.openhab.org/t/dashboard-ui-suitable-for-tablets/2329)

Hi, I’m using OH2 with dashing by using mqtt as transporter.
You dont require scheduled jobs on both sides, as it is"pushed" by the broker.
I like this way more than curl or httprequests.
I only did some tests with contacts and values, which worked without any issues, but not with commandsfrom dashing…which is my next focus.

Yes, that would work. I’m not sure of the benefit as it is still adding another layer. By using sendHttpPostRequest, we are posting directly to the Dashing API - so no additional layers and no scheduled jobs. What will be more interesting is the use of SSE that OH2 supports. @beowulfe has already started on this - see Dashboard UI suitable for tablets.

I’m using Dashing with OH2.

Some changes to the rules file, mainly to take account of NULL and UNDEF values. The POST sends to the API OK and I see the values update. However, I get a null pointer exception (later added a try/catch around it) which I think may be due to the response having no data (204 response):

2016-04-07 17:33:00.473 [INFO ] [pse.smarthome.model.script.Dashboard] - URI: http://localhost:3030/widgets/Boiler; JSON = {"auth_token" : "openH4b",  "state" : "ON"}
2016-04-07 17:33:00.475 [DEBUG] [.httpclient.params.DefaultHttpParams] - Set parameter http.socket.timeout = 1000
2016-04-07 17:33:00.476 [DEBUG] [.httpclient.params.DefaultHttpParams] - Set parameter http.method.retry-handler = org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@39116
2016-04-07 17:33:00.477 [DEBUG] [he.commons.httpclient.HttpConnection] - Open connection to localhost:3030
2016-04-07 17:33:00.480 [DEBUG] [httpclient.wire.header              ] - >> "POST /widgets/Boiler HTTP/1.1[\r][\n]"
2016-04-07 17:33:00.481 [DEBUG] [he.commons.httpclient.HttpMethodBase] - Adding Host request header
2016-04-07 17:33:00.481 [DEBUG] [org.eclipse.jetty.io.IdleTimeout    ] - SelectChannelEndPoint@ee0030{/192.168.0.116:49277<->8080,Open,in,out,R,-,9798/30000,HttpConnection}{io=1,kio=1,kro=1} idle timeout check, elapsed: 9798 ms, remaining: 20202 ms
2016-04-07 17:33:00.482 [DEBUG] [httpclient.wire.header              ] - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
2016-04-07 17:33:00.482 [DEBUG] [httpclient.wire.header              ] - >> "Host: localhost:3030[\r][\n]"
2016-04-07 17:33:00.483 [DEBUG] [httpclient.wire.header              ] - >> "Content-Length: 43[\r][\n]"
2016-04-07 17:33:00.483 [DEBUG] [httpclient.wire.header              ] - >> "Content-Type: HTTP.CONTENT_TYPE_JSON[\r][\n]"
2016-04-07 17:33:00.484 [DEBUG] [httpclient.wire.header              ] - >> "[\r][\n]"
2016-04-07 17:33:00.484 [DEBUG] [httpclient.wire.content             ] - >> "{"auth_token" : "openH4b",  "state" : "ON"}"
2016-04-07 17:33:00.485 [DEBUG] [client.methods.EntityEnclosingMethod] - Request body sent
2016-04-07 17:33:00.490 [DEBUG] [httpclient.wire.header              ] - << "HTTP/1.1 204 No Content[\r][\n]"
2016-04-07 17:33:00.491 [DEBUG] [httpclient.wire.header              ] - << "HTTP/1.1 204 No Content[\r][\n]"
2016-04-07 17:33:00.492 [DEBUG] [httpclient.wire.header              ] - << "X-Content-Type-Options: nosniff[\r][\n]"
2016-04-07 17:33:00.492 [DEBUG] [httpclient.wire.header              ] - << "Connection: close[\r][\n]"
2016-04-07 17:33:00.493 [DEBUG] [httpclient.wire.header              ] - << "Server: thin 1.6.2 codename Doc Brown[\r][\n]"
2016-04-07 17:33:00.493 [DEBUG] [httpclient.wire.header              ] - << "[\r][\n]"
2016-04-07 17:33:00.493 [DEBUG] [he.commons.httpclient.HttpMethodBase] - Should close connection in response to directive: close
2016-04-07 17:33:00.494 [DEBUG] [he.commons.httpclient.HttpConnection] - Connection is locked.  Call to releaseConnection() ignored.
2016-04-07 17:33:00.494 [DEBUG] [he.commons.httpclient.HttpConnection] - Releasing connection back to connection manager.
2016-04-07 17:33:00.496 [ERROR] [.script.engine.ScriptExecutionThread] - Error during the execution of rule 'Post changes to Dashing Dashboard'
java.lang.NullPointerException
	at java.io.Reader.<init>(Reader.java:78)[:1.8.0_65]

Change to the ohapp.rb to change the sendCommand to /classicui/CMD

Of course, SSE is the way to go but for now…