Instanceof org.codehaus.groovy.grails.web.json.JSONObject Equivalent

Greetings,

I’m trying to get the Wireless Tags working and I’ve gotten the same error on line 898. Where would I include the import statement?

Imports go up at the top

1 Like

Thank you. I tried adding the import statement and nothing changed. Any other suggestions?

I think there was a bug in SmartThings where runIn would pass the object in as a JSONObject instead of a map so a lot of SmartApps have checks to see what they are working in so they access attributes properly. Did we ever get an answer here, or maybe it’s that this platform doesn’t have this bug and we can assume we’ll get a map?

I finally decided to start attacking the wireless tags again. Here’s the first piece of code in question:

def toJson(Map m)
{
return new org.codehaus.groovy.grails.web.json.JSONObject(m).toString()
}

When I remove the “new” then it saves correctly. Does that mean that it’s a syntax issue?

Any luck with this? I've tried a few times now and can't get anywhere with it.

Thanks

What are you trying to do...convert a string to Json or map?
If so, I have had success using evaluate(string). All other methods have been hit or miss...primarily miss.

Still poking around with the Wireless Tag code from ST. Trying to get it to run here.

def toJson(Map m)
{
return new org.codehaus.groovy.grails.web.json.JSONObject(m).toString()
}

This is the error:
unable to resolve class org.codehaus.groovy.grails.web.json.JSONObject @ line 879, column 9.

Can you post a link to the complete code?

Sure ...

How about this
return new groovy.json.JsonBuilder(m).toString()

1 Like

That got us past the error! Thank you!

Now to work out the Authentication. It goes to the website to login. Then once I login and it asks me if I want to grant access to ST. When I say yes I get this:

{"message":"Missing Authentication Token"}

Looks like this is what needs fixing:

def buildRedirectUrl()
{
	log.debug "buildRedirectUrl"
	return apiServerUrl("/api/token/${atomicState.accessToken}/smartapps/installations/${app.id}/swapToken")
}

Documentation for getting a local or cloud endpoint can be found in this post...

Yes, I have seen this but not being a programmer, I need working examples to compare not just some technical wording. Unfortunately I'm way over my head on this but since it hasn't been looked at in months, I figure I could waste a couple of hours poking around, lol.

If nothing else comes of this today, at least @stephack got us past the first hurdle. Hopefully someone can figure out the oath part. :grin: I know it won't be me! But if I keep asking questions, sometimes I can put the pieces together.

I'm am also not a programmer so I wouldn't necessarily assume that the code I posted is accurate...even if it avoids an error. If you still have these devices in ST, I would add an output to the logs from the toJson method in both ST and HE and compare the results. Just to ensure they at least look similar.

With oauth I have absolutely no experience.

1 Like

Also found this post. Very good read, if I could only connect the dots. I'll get there!

I too have been following this and am stuck as well.. anyone find any work-arounds?

I took the plunge recently and got a version swanny's SmartThings WirelessTags working on my Hubitat: Hubitat/WirelessTags at master · bhazer/Hubitat · GitHub

This thread was super helpful. Thanks all for the advice in here!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.