Devicetree error:

devicetree API internally uses sockets and thus ‘yield’ (i.e. block), when waiting for data on the socket (until the data arrives). In Lua 5.1 there is a limitation that is you cannot yield across a C method. pcall is a C method (Lua API implemented in C).
For this reason an yield compatible pcall is provided.

In your code please do
require ‘coxpcall’

then replace pcall() by copcall() (same prototype)

More info on this here: keplerproject.github.io/coxpcall/