Analog Clock demo help

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?

It from this: https://github.com/info-beamer/package-screen-info/blob/master/node.lua

Apparently I haven’t figured out how Info-Beamer is working. I haven’t implemented the “service” for this. I thought it was something standard in Lua.
So let me get this right. If I want to use the “util.data_mapper” - I also need to implement something in the “service” file - and not in the “clock.py” file?

Not quite. Let me explain: info-beamer (the process on each Raspberry Pi) always opens up a local UDP/TCP listen socket on port 4444. This allows other local processes to send data to the running info-beamer process. This can be useful as info-beamer (again, the process) itself cannot, for example, contact any outside service on its own. So it needs to be fed additional non-static data in some way. Using UDP/TCP for that is one way to do that.

Now there are various ways you can do that: If you open the info-beamer port to other machines on the network (here for how to do that, but doing so it usually not recommended as there’s no authentication in any way), another program on another machine can send data. That’s what my netcat call in my previous post did. Another way is to use the device command API call, which essentially allows you to send such UDP packets from anywhere using the API.

The final method is to have a local package service running on each Pi. This isn’t something magic: It’s just that any file named service within a package will be marked executable and will be executed on the Pi when installing that package. Such a package service can be written Python, like this one in the repository you linked. Such a service can also send UDP packets locally to the info-beamer process by sending data to 127.0.0.1:4444.

AH! That’s why the clock is not working. The demo code (https://github.com/dividuum/info-beamer-nodes/tree/master/analogclock) contains a “clock.py” and not a “service” file :slight_smile:

Yep. That’a also from a time when info-beamer hosted didn’t exist yet. So there was no convention on how anything outside of info-beamer or its Lua code should be named. The service name and the special handling that ensured that such a file is executed on a Pi was added to hosted.

If you run info-beamer pi on Raspbian, you can of course name those scripts any way you want, but that’s it’s up to you to ensure they are executed somehow. As that’s boring, info-beamer hosted solves that for you :slight_smile:

1 Like

Another problem seems to be that datetime is no longer supported :upside_down_face:

.py:

from hosted import datetime

It’s import datetime. See https://docs.python.org/library/datetime.html

1 Like