info-beamer

Analog Clock demo help

Hi
I’m trying to implement a clock in my own package but I’m having a problem with getting the initial time.
I’m using this demo: https://github.com/dividuum/info-beamer-nodes/tree/master/analogclock and I think that the problem is the line in the python script:

sock.sendto(‘analogclock/clock/set:%d’ % since_midnight, (‘127.0.0.1’, 4444))

I have tried to replace the “analogclock” with my packet name, but it does not seems to work :-/

Any clue to what I can do to find the problem?

The analogclock part here is the name of the top-level node. The code you linked is quite old and from a time where info-beamer on the Pi didn’t even exist. When you ran info-beamer and gave the analogclock directory as argument, the top level node is named analogclock. Or more generalized: Starting info-beamer with info-beamer /path/to/some-directory will result in the top leven node being named some-directory.

The UDP addressing expects the full node path, including the top-level node. So the above call expects that node to be named analogclock.

Now on hosted, all the Lua top level code always ends up in /space/root, so the top-level node is always named root. If you change the value to root/clock/set:... it should work.

1 Like

This didn’t seem to work (https://info-beamer.com/package/11389)

I have changed it to:

sock.sendto('root/clock/set:%d' % since_midnight, ('127.0.0.1', 4444))

and in my lua file:

util.data_mapper{
    state = function(state)
        button = state == '0'
    end,

  ["clock/set"] = function(time)
            base_time = tonumber(time) - sys.now()
            N.base_time = base_time
        end
}

What happens? At first sight, it looks correct. I would suggest you add a debug print output to the callback to see if it ends up being called.

Where do I see the “print”. It’s not shown on the screen.

In the local log output:

logread -f | grep info-beamer:
1 Like

It seems that I can’t login using ssh.
Putty gives me a time-out and Linux: ssh: connect to host 172.16.1.150 port 22: Resource temporarily unavailable

Authorization file is added and is working on other systems

Using the web terminal I can see that “print” in lua is not showing in the log, but I got this.

Apr 30 10:48:39 Micro user.notice service.root: [hosted.py] sending 'root/state:0'
Apr 30 10:48:39 Micro user.notice info-beamer: [root] button
Apr 30 10:48:40 Micro user.notice service.root: [hosted.py] sending 'root/state:1'
Apr 30 10:48:40 Micro user.notice info-beamer: [root] button
Apr 30 10:48:41 Micro user.notice service.root: [hosted.py] sending 'root/state:0'
Apr 30 10:48:42 Micro user.notice info-beamer: [root] button
Apr 30 10:48:43 Micro user.notice service.root: [hosted.py] sending 'root/state:1'
Apr 30 10:48:43 Micro user.notice info-beamer: [root] button

This means that I can’t use “print” for debugging :frowning:

Not sure I understand: The line

Apr 30 10:48:39 Micro user.notice info-beamer: [root] button

is the result of a print("button") somewhere.

I have added a debug string to:

util.data_mapper{
    state = function(state)
        debugtxt = debugtxt .. " button "
        button = state == '0'
    end,

    ["device_info"] = function(info)
        debugtxt = debugtxt .. "device_info"
        info = json.decode(info)
        location = info.location
        description = info.description
    end,

    ["clock/set"] = function(time)
        debugtxt = debugtxt .. "Clock/set"
        base_time = tonumber(time) - sys.now()
        N.base_time = base_time
    end
}

This is empty, so it seems that util.data_mapper is never called.

Just to be sure: This is the node.lua of the top-level directory, correct? So it’s not part of a package that is added as a child within a setup (similarly to how the power saver package is usually used).

You can also increase the log level by running pkill -usr2 info-beamer on the device once. This will increase the debug level from 3 to 4 and the log will be filled with a lot more information. The UDP message should be in there, but I can’t tell you what to grep for right now. I think using logread -f|grep -i udp should show something though.

Don’t know where that came from. I added a lot of “print” statements, but I’m not sure I added just one saying “button”.

The code on the device is the correct one? Is node.lua what you expect it to be?

Ok - figured out that the “button” was my code in data_mapper. Just got confused as no other print code was executed.

util.data_mapper{
    state = function(state)
        print " Button state changed "
        button = state == '0'
    end,

    ["device_info"] = function(info)
        print "device_info"
        info = json.decode(info)
        location = info.location
        description = info.description
    end,

    ["clock/set"] = function(time)
        print "Clock/set"
        base_time = tonumber(time) - sys.now()
        N.base_time = base_time
    end
}

When I press the button I get this:

Apr 30 11:07:42 Micro user.notice info-beamer: [root] Button state changed

but the other two functions seems never to be called.

Hm. I can take a look later to see what’s going on. The code looks correct, so it’s probably something minor. Which setup/device is that? Can you leave it running for a few hours?

Did the pkill command above yield any log lines? You should see something when you logread -f|grep state and trigger the state callback. A similar line will be generated when you send the clock/set message. Do they show up?

(https://info-beamer.com/package/11389)

The log shows nothing:

Micro /space/root $ pkill -usr2 info-beamer
Micro /space/root $ logread -f | grep state

Oh. Correct. The log output doesn’t actually include the sent value itself. My bad. Instead you get a line like this:

[..] info-beamer: [main.c] udp packet (len 17) received from 127.0.0.1:43140

I pasted your code into a mostly empty node.lua file and cannot reproduce the problem:

First I restarted info-beamer to reset the log level to 3, the increased it to 4 using pkill and then tailed the log:

info-beamer-3689967300 /space/root # sv i /service/info-beamer
info-beamer-3689967300 /space/root # pkill -usr2 info-beamer
info-beamer-3689967300 /space/root # logread -f|grep -v frame

Terminal output (slightly cut to make it fit a bit better):

info-beamer: [main.c] udp packet (len 19) received from 192.168.1.147:50038
info-beamer: [root] Clock/set
info-beamer: [root] runtime error: [...]

The error is expected, as the code after the print bugs out as it’s an almost empty node.lua, but as you can see the print("Clock/set") is executed.

On another machine, I triggered this running:

fw@somebox:~$ echo -en 'root/clock/set:1234' | netcat -u 192.168.1.165 4444

Are there maybe multiple util.data_wrapper “blocks” within your node.lua file? Do you have child nodes? How do you try to trigger this? Using Python? What exactly do you send there?

When using the terminal output you are using I just get a million lines:

May 1 08:27:09 Micro user.notice info-beamer: [main.c] frame time 0.0167
May 1 08:27:09 Micro user.notice info-beamer: [font.c] buffered rendering 72 vertices from 1
May 1 08:27:09 Micro user.notice info-beamer: [font.c] buffered rendering 108 vertices from 2
May 1 08:27:09 Micro user.notice info-beamer: [font.c] buffered rendering 54 vertices from 3
May 1 08:27:09 Micro user.notice info-beamer: [font.c] buffered rendering 168 vertices from 4
May 1 08:27:09 Micro user.notice info-beamer: [font.c] buffered rendering 138 vertices from 5
May 1 08:27:09 Micro user.notice info-beamer: [font.c] buffered rendering 90 vertices from 6

The util.data_mapper is executes when I press the button, but e.g. the [“device_info”] section is never called (I never get location and description filled) - and as far as I can see neigher is the [“clock/set”] section

Using grep root I get these lines when updating the package:

May 1 08:35:51 Micro user.notice info-beamer: [root] update +COPYRIGHT (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +README.md (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +arial.ttf (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +clock.py (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +config.json (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +hosted.py (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +node.json (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +package.json (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +package.png (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +service (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] update +node.lua (search)
May 1 08:35:51 Micro user.notice info-beamer: [root] [kernel] node code updated. booting …
May 1 08:35:51 Micro user.notice info-beamer: [root] [kernel] flushed vm. collected 0kb. 123kb in use
May 1 08:35:51 Micro user.notice info-beamer: [root] [kernel] loading bundled userlib.lua (‘info-beamer -d userlib’)
May 1 08:35:51 Micro user.notice info-beamer: [root] [userlib] loading bundled module ‘struct’
May 1 08:35:51 Micro user.notice info-beamer: [root] loading root/node.lua
May 1 08:35:51 Micro user.notice info-beamer: [root] loading root/arial.ttf
May 1 08:35:51 Micro user.notice info-beamer: [font.c] loading root/arial.ttf (1027192 byte)
May 1 08:35:51 Micro user.notice info-beamer: [font.c] kerning for font root/arial.ttf: 1
May 1 08:35:51 Micro user.notice info-beamer: [root] loading root/config.json
May 1 08:35:51 Micro user.notice info-beamer: [root] [userlib] loading bundled module ‘json’
May 1 08:35:51 Micro user.notice info-beamer: [root] [kernel] node booted. 171kb in use
May 1 08:36:01 Micro user.notice info-beamer: 185kb 59.6 800 800 2.0% R-s- '- root (-)
May 1 08:36:11 Micro user.notice info-beamer: 185kb 59.9 800 800 1.0% R-s- '- root (-)

No lines containing
print “device_info”
print “Clock/set”

I imported the package into my account, assigned it to a device, exposed info-beamer to the network (otherwise it’s completely unreachable from outside the device) and then sent the packet using:

fw@somebox:~$ echo -en "root/clock/set:123"| netcat -u 192.168.1.181 4444

That worked and resulted in the following log output on the device:

May  1 [..snip..] user.notice info-beamer: [root] DEBUG: Clock/set

So there must be some small difference in how you approach this somewhere. How and from where do you send the device_info packet for example? What’s the exact code for that? Is that from another machine in the network?

info-beamer - Digital Signage for the Raspberry Pi community forum - Imprint