# Analog Clock demo help

**URL:** <https://community.info-beamer.com/t/analog-clock-demo-help/869>\
**Category:** How-to and Tutorials\
**Created:** [April 29, 2020, 10:59am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869 "2020-04-29T10:59:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 29, 2020, 10:59am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/1 "2020-04-29T10:59:46Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [April 29, 2020, 11:07am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/2 "2020-04-29T11:07:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 30, 2020, 7:46am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/3 "2020-04-30T07:46:36Z")

</div>

This didn’t seem to work ([https://info-beamer.com/package/11389](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
}
```

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [April 30, 2020, 9:23am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/4 "2020-04-30T09:23:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 30, 2020, 10:10am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/5 "2020-04-30T10:10:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [April 30, 2020, 10:13am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/6 "2020-04-30T10:13:45Z")

</div>

In the local log output:

```auto
logread -f | grep info-beamer:

```

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 30, 2020, 10:43am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/7 "2020-04-30T10:43:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 30, 2020, 10:51am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/8 "2020-04-30T10:51:20Z")

</div>

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 ☹

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [April 30, 2020, 10:56am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/9 "2020-04-30T10:56:18Z")

</div>

> [@Wassini](#):
>
> This means that I can’t use “print” for debugging ☹

Not sure I understand: The line

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

```

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

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 30, 2020, 10:57am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/10 "2020-04-30T10:57:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [April 30, 2020, 11:02am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/12 "2020-04-30T11:02:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 30, 2020, 11:02am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/13 "2020-04-30T11:02:51Z")

</div>

> [@infobeamer-fw](#):
>
> is the result of a `print("button")` somewhere.

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”.

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [April 30, 2020, 11:04am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/14 "2020-04-30T11:04:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 30, 2020, 11:11am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/15 "2020-04-30T11:11:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [April 30, 2020, 11:49am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/16 "2020-04-30T11:49:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [April 30, 2020, 12:00pm UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/17 "2020-04-30T12:00:35Z")

</div>

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

The log shows nothing:

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

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [April 30, 2020, 5:53pm UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/18 "2020-04-30T17:53:19Z")

</div>

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

```auto
[..] 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:

```nohighlight
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):

```nohighlight
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:

```nohighlight
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?

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [May 1, 2020, 8:33am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/19 "2020-05-01T08:33:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Wassini](https://community.info-beamer.com/user_avatar/community.info-beamer.com/wassini/32/203_2.png) [@Wassini](https://community.info-beamer.com/u/Wassini)\
**Post date:** [May 1, 2020, 8:38am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/20 "2020-05-01T08:38:22Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![infobeamer-fw](https://community.info-beamer.com/user_avatar/community.info-beamer.com/infobeamer-fw/32/3_2.png) [@infobeamer-fw](https://community.info-beamer.com/u/infobeamer-fw)\
**Post date:** [May 1, 2020, 10:47am UTC](https://community.info-beamer.com/t/analog-clock-demo-help/869/21 "2020-05-01T10:47:13Z")

</div>

I imported the package into my account, assigned it to a device, [exposed info-beamer to the network](https://info-beamer.com/doc/device-configuration#exposeinfobeamerports) (otherwise it’s completely unreachable from outside the device) and then sent the packet using:

```auto
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:

```auto
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?

[Next page](https://community.info-beamer.com/t/analog-clock-demo-help/869.md?page=2)
