Callback or event signalling from c to python

Hi there! Are there any examples you may share on the following scenarios?

  1. Calling a python function/sub from a C program?
  2. Sincronizing C and python by means of an “Event”

What I’m looking into is to reuse the http_server example from espressif and somehow “calling” python when we receive a valid request.

Regards
Alex

Hi @Alex1
Currently, it is therefore possible to call C functions from Python, but not (yet) Python functions from C.
Check this doc for more info on C language interface.
However, I think there is a workaround until this feature is implemented. (But not a clean approach :sweat:)
You can have a C function that checks for event, A python function that calls this C function and checks if a flag has been raised. and a python thread that uses this python function.

@native_c("_get_event",["HTTPserver_c_stuff.c"],[])
def _get_event():
    pass

def _event_loop():
    try:
        while True:
            evt_type = _get_event()
            if evt_type == 0: # EVENT
                #do Stuff
           
    except Exception as e:
        pass

def start():
    thread(_event_loop)

Let me know if you are developing a commercial product, If so, this feature could be arranged with the Zerynth team.

Hi @karimhamdy1, sorry for the late reply.
Yes I’m developing a commercial product.

With regard to this thread I decide to go classic python only and work with the timeouts until Zerynth gives us callbacks for sockets, I just started a thread to handle all sockets comms and seem to work fine.

Thanks any way.

Best regards
Alex

1 Like

hi @Alex1,
We’ll be starting our Zerynth Live Support session on YouTube today , where we will answer your question (and a couple of others). @karimhamdy1 will be holding the session.

If you would like to join us on our YouTube channel, the live session starts at 4 pm (CET). And of course, if you have any other questions you can either ask in the comment section on the video.

Here’s the link to the Zerynth YT channel in case you’re interested in joining us: http://www.youtube.com/c/Zerynth