Page 4 of 4 FirstFirst ... 234
Results 31 to 37 of 37

Thread: plugin question

  1. #31
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok i went to add in the timer and I get this error
    Code:
    Tue Jan 20 19:38:40 2015	LuaTimerObject::ontimeout / ...am Files/Promixis/Girder 6/lua/rpitemp\component.lua:32: attempt to index local 'self' (a nil value)
    Tue Jan 20 19:38:40 2015	stack traceback:
    Tue Jan 20 19:38:40 2015		...am Files/Promixis/Girder 6/lua/rpitemp\component.lua:32: in function 'update'
    Tue Jan 20 19:38:40 2015		...am Files/Promixis/Girder 6/lua/rpitemp\component.lua:67: in function <...am Files/Promixis/Girder 6/lua/rpitemp\component.lua:65>
    Here is the code from the component.lua.
    Code:
    local base = require("plugin.component")
    local print = print
    local Promixis = Promixis
    local bit = require('bit')
    local json = require('json')
    local string = require('string')
    local gir = gir
    local tonumber = tonumber
    local tostring = tostring
    local table = require('table')
    local ipairs = ipairs
    local type=type
    local timer = require('timer')
    module(...)
    
    base:subclass(_M)
    
    
    local function update(self)
    	
    		--sensor 1 28-0000057a5128
    		self:forEachDevice( function ( internalId, device ) 			
    			print("comp test")		
    			print (internalId)
    			--[[
    			local f = assert(io.open("/sys/bus/w1/devices/".. internalId .."/w1_slave", "r")) --replace 28-0000057a5128 with the serial from your sensor can be got from tenminal at /sys/bus/w1/devices/
    			local t = f:read("*all")
    			tpos = string.find(t, "t=") --find t= in sensor data
    			tpos= tpos + 2  
    			temp = t:sub( tpos )
    			rtemp = temp/1000 --convert temp in cal to deciamal
    			--print(rtemp)--test converstion to dec
    			ftemp = rtemp * 9 / 5 + 32 --convert temp to F
    			ftemp = math.round(ftemp*10)*0.1 --round to single decimal
    			print ("f temp "..ftemp) --test convert temp to F
    			--print(t) --test read sensor input
    			f:close()--]]
    			local ctrl = device:findControl("t1")
    			--table.print (ctrl) -- test find control tor sensor tempeture
    			ctrl:setValue("62")
    
    		end)
    	
    	
    end
    
    --[[function start(self)
    	base.start(self)
    	update(self)
    end
    --]]
    --[[
    start timer to run automatic parsing
    --]]
    local timerObj = timer.new(10000, function(t)
      print("hello")
      update(self)
    end)
     
    timerObj:start()
    
    --[[
    end timer to run automatic parsing
    --]]
    Thanks,
    Yonu

  2. #32
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    You placed the timer outside of a function that gets 'self'.

    Code:
    local base = require("plugin.component")
    local print = print
    local Promixis = Promixis
    local bit = require('bit')
    local json = require('json')
    local string = require('string')
    local gir = gir
    local tonumber = tonumber
    local tostring = tostring
    local table = require('table')
    local ipairs = ipairs
    local type=type
    local timer = require('timer')
    module(...)
    
    base:subclass(_M)
    
    
    local function update(self)
        
            --sensor 1 28-0000057a5128
            self:forEachDevice( function ( internalId, device )             
                print("comp test")        
                print (internalId)
                --[[
                local f = assert(io.open("/sys/bus/w1/devices/".. internalId .."/w1_slave", "r")) --replace 28-0000057a5128 with the serial from your sensor can be got from tenminal at /sys/bus/w1/devices/
                local t = f:read("*all")
                tpos = string.find(t, "t=") --find t= in sensor data
                tpos= tpos + 2  
                temp = t:sub( tpos )
                rtemp = temp/1000 --convert temp in cal to deciamal
                --print(rtemp)--test converstion to dec
                ftemp = rtemp * 9 / 5 + 32 --convert temp to F
                ftemp = math.round(ftemp*10)*0.1 --round to single decimal
                print ("f temp "..ftemp) --test convert temp to F
                --print(t) --test read sensor input
                f:close()--]]
                local ctrl = device:findControl("t1")
                --table.print (ctrl) -- test find control tor sensor tempeture
                ctrl:setValue("62")
    
            end)
        
        
    end
    
    function start(self)
        base.start(self)
        
        self.timerObj = timer.new(10000, function(t)
          print("hello")
          update(self)
        end) 
        self.timerObj:start()    
    end
    
    function stop(self)
        self.timerObj:deinit()
        self.timerObj = nil
        
        base.stop(self)    
    end
    Ron
    No support through PM

  3. #33
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok I just transfered the plugin over to a Raspberry and I get these errors any ideas not sure why it is complaining about io I tested the io codes in a scripting action first and it has been working
    Code:
    Tue Jan 20 21:08:38 2015	LuaTimerObject::ontimeout / /opt/girder/lua/rpitemp/component.lua:36: attempt to index global 'io' (a nil value)
    Tue Jan 20 21:08:38 2015	stack traceback:
    Tue Jan 20 21:08:38 2015		/opt/girder/lua/rpitemp/component.lua:36: in function 'cb'
    Tue Jan 20 21:08:38 2015		/opt/girder/lua/plugin/component.lua:31: in function 'forEachDevice'
    Tue Jan 20 21:08:38 2015		/opt/girder/lua/rpitemp/component.lua:32: in function 'update'
    Tue Jan 20 21:08:38 2015		/opt/girder/lua/rpitemp/component.lua:63: in function </opt/girder/lua/rpitemp/component.lua:61>
    Tue Jan 20 21:08:48 2015	LuaTimerObject::ontimeout / /opt/girder/lua/rpitemp/component.lua:36: attempt to index global 'io' (a nil value)
    Thanks,
    Yonu

  4. #34
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,550

    Default

    You are missing the io include at the top:

    Code:
    local io = require('io')
    Ron
    No support through PM

  5. #35
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok odd it worked without it in a regular script

    Thanks,
    Yonu

  6. #36
    Join Date
    Mar 2005
    Posts
    724

    Default

    I assume this is another require?

    Wed Jan 21 09:14:58 2015 LuaTimerObject:ntimeout / /opt/girder/lua/rpitemp/component.lua:37: attempt to call global 'assert' (a nil value)
    Wed Jan 21 09:14:58 2015 stack traceback:
    Wed Jan 21 09:14:58 2015 /opt/girder/lua/rpitemp/component.lua:37: in function 'cb'
    Wed Jan 21 09:14:58 2015 /opt/girder/lua/plugin/component.lua:31: in function 'forEachDevice'
    Wed Jan 21 09:14:58 2015 /opt/girder/lua/rpitemp/component.lua:33: in function 'update'
    Wed Jan 21 09:14:58 2015 /opt/girder/lua/rpitemp/component.lua:64: in function </opt/girder/lua/rpitemp/component.lua:62>

  7. #37
    Join Date
    Mar 2005
    Posts
    724

    Default

    ok thanks got it working will post the plugin as soon as I clean up the code and add in comments well and request a plugin number

Page 4 of 4 FirstFirst ... 234

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •