Internal Server Error


#1

So here is a bit of my app that is giving me headaches

mappings {

	path("/setVal/:thevalue") {
		action: [
			GET: "resetAtomic"
		]
	}
	path("/runLog/:myvalue") {
		action: [
			GET: "logData"
		]
	}
}

def resetAtomic() {
	log.debug "running resetAtomic"
	atomicState.previousEnergy=0
}


def logData() {
log.debug "Running Log Data"
}

This URL works fine
https://graph.api.smartthings.com/api/smartapps/installations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/runLog/234?access_token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

This URL gives the Server error.
https://graph.api.smartthings.com/api/smartapps/installations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/setVal/234?access_token=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Why?

The codes in the URL have been replaced with xxxx but they were/are identical for each url. I am totally confused why one url works fine while the other does not


(Ben W) #2

What is the :myValue and :the value being used for?

If you remove “atomicState.previousEnergy=0” does it work?


#3

In the example I showed above, nothing.

Yes!!! The above example is a stripped down version of the actual app. The function resetAtomic() show is identical to the actual code. Removing the line atomicState.previousEnergy=0 will eliminate the error suggesting a problem with assigning atomic state values this way. However…

The “complete” function logData() does exactly the same further down in the code.

def logData() {
log.debug "Running Log Data"
	def hourMinus1=now() - 3600000
	def stamp = new Date(hourMinus1).format('dd-MMM-yyyy HH:mm:ss',location.timeZone)
    def power1 = sensor1.currentValue("power1")
    def power2 = sensor1.currentValue("power2")
	def latestPower = sensor1.currentValue("power")
    
	def current1= sensor1.currentValue("current1")
    def current2= sensor1.currentValue("current2")
	def totAmps = sensor1.currentValue("current")

    def lineLossFactor=adjustFactor.toDouble()

	def latestVoltage = sensor1.currentValue("voltage")
	def curEnergy=sensor1.currentValue("current").toDouble()
 	def cumilativeCurrent = sensor1.currentValue("energy")
   	def hourlyEnergyUsage=Math.round((cumilativeCurrent-atomicState.previousEnergy) * 100) /100
    def hourlyEnergyAdjusted=hourlyEnergyUsage * lineLossFactor
    
    calcRate()    
    def hourlyCost=hourlyEnergyUsage * atomicState.currentRate
    def rateUsed = atomicState.currentRate

	atomicState.previousEnergy=cumilativeCurrent

.
This atomic assignment does not raise the same error Makes no sense to me


(www.rboyapps.com - Make your home your butler!) #4

does it work with state instead of atomicState?

EDIT: Also if I remember correctly setting

atomicState.previousEnergy=0

Will do nothing, previousEnergy will not be stored (it’s got to be a non 0, non null, non empty value for it to save the value to atomicState), unless the behavior has changed in the past few months.


(Ben W) #5

Wondering if previousEnergy is a protect name. Ran into that yesterday trying to set a variable to “switch”. (stab in the dark)

Whats the full error in live logging?

Maybe atomicState.previousEnergy can’t take a number/double. Try sending a string. Maybe it was initialized as a string before. log.debug out its value, same with cumilativeCurrent.


#6

Now that is very possible. I gave up looking for the reason as I found an alternate way of doing this. The only reason for the atomicState.previousEnergy=0 statement is to clear (reset) the old value after the device (and its values such as cumulativeEnergy) itself is “reset” within the Device Handler. I found that this statement was unnecessary and handled it differently.

Thanks everyone for your suggestions and getting me thinking :slight_smile: