Please help: Cannot get Input Values to post other than "0" to feed

I’ve got some LUA code running on a Vera Plus. Unfortunately, the variables all post “0” values.

Any ideas? Below is the Lua code from my Vera Plus device. I’ve also included a link to the Vera forum (where no one seems to read/reply).

module("EnergyMonitor", package.seeall)

-- Setup your account at http://emoncms.org/
-- See API documentation at http://emoncms.org/input/api

-- API Key
local API_KEY = "REMOVED FOR SECURITY REASONS"

-- Setup your devices here. You can use a function to calculate the power as illustrated in the sample.
-- For device logging, use: key, deviceId, serviceId, serviceVar
-- For function based logging, use: key, calculate, serviceVar

local VARIABLES = {
	{ key="HEM", deviceId = 155, serviceId='urn:schemas-micasaverde-com:device:PowerMeter:1', serviceVar="Watts" },
	{ key="HEM", deviceId = 155, serviceId='urn:schemas-micasaverde-com:device:PowerMeter:1', serviceVar="CurrentLevel" },
	{ key="kilnwelder", deviceId = 135, serviceId='urn:schemas-micasaverde-com:device:PowerMeter:1', serviceVar="Watts" },
	{ key="kilnwelder", deviceId = 135, serviceId='urn:schemas-micasaverde-com:device:PowerMeter:1', serviceVar="CurrentLevel" },
    { key='TestVar', calculate=function() return 15 end, serviceVar="dsmtest" } -- Send a constant value
}

-- Add the following to your Vera's Startup Lua (without the preceding dashes) to run the logging on every Vera restart
-- emoncode = require("EnergyMonitor")
-- emoncode.EnergyMonitorOnTimer()

local NODE_ID = 10
local TOTAL_KEY = 'Total'


-- Upload Frequency in seconds ORIGINALLY 60
local updateInterval = 10

-- Log debug messages
local DEBUG = true


-- You shouldn't need to change anything below this line --


local http = require('socket.http')
http.TIMEOUT = 3

local BASE_URL = "http://emoncms.org/input/post.json?apikey=" .. API_KEY
local Log = function (text) luup.log('EnergyMonitor Logger: ' .. (text or "empty")) end
local lastFullUpload = 0

local items = {} -- contains items: { time, deviceId, value }

local function StartCallbackTimer(interval)
	luup.call_delay("EnergyMonitorOnTimer", interval or updateInterval, nil)
end

local function InitWatch()
	StartCallbackTimer(1)
end

local function AddKeyValuePair(key, value)
	local item = string.format("%s:%s", key, tostring(value))
	items[#items + 1] = item
end

local function SerializeData()
	local dataText = "{" .. table.concat(items, ",") .. "}"
	return dataText
end

local function ResetData()
	items = {}
end

local function SendData()
	local data = SerializeData()
	ResetData()

	local parameters = "&node=" .. tostring(NODE_ID) .. "&json=" .. data
	local url = BASE_URL .. parameters
	if (DEBUG) then Log("Updating with: " .. parameters) end
	http.request(url)
end

local function AddAllVariablesAndTotal()
	local total = 0
	for i, v in ipairs(VARIABLES) do
		local value
		if v.deviceId then
			value = luup.variable_get(v.serviceId, v.serviceVar, v.deviceId)
		elseif v.calculate then
			value = v.calculate()
		end
		value = tonumber(value) or 0
		if v.serviceVar == "Watts" then
			total = total + value
		end
		AddKeyValuePair(v.key, value)
	end
	AddKeyValuePair(TOTAL_KEY, total)
end

function EnergyMonitorOnTimer()
	StartCallbackTimer()
	AddAllVariablesAndTotal()
	SendData()
end

_G.EnergyMonitorOnTimer = EnergyMonitorOnTimer
InitWatch()

http://forum.micasaverde.com/index.php/topic,35953.msg321520.html#msg321520

Disclaimer: I don’t know the first thing about the language.

However, can you construct a fixed string like one of the examples in the emoncms API Help, and send that? If that works, it shows that the problem is within your code, and not with actually sending it.

If it does work, my bet would be that either the format that your code constructs is wrong, or somewhere, numbers and strings are getting mixed up, and you need to look carefully at what each function expects for its parameters, and at what it returns.
(In many languages, a string will evaluate to zero if a number was expected.)

Can you put fixed values into the VARIABLES array to prove whether getting the values is or is not the problem?

You are using your “read & write” API Key?

Note that emoncms.org only allows one post every 10 s.