Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Mixing bluetooth with websockets in C program. Need some help

Preface; i have little to no C experience.

What works:
I have implemented a bluetooth low energy HID keyboard peripheral which runs on my Rasberry Pi. From my Android Shield TV i can pair with this keyboard.

What i want to achieve:
I want to implement websockets in my peripheral, so that eventually i can send a command to my Bluetooth Peripheral (e.g. running on an ESP32 or any other unattended system) which forwards keypresses to my paired device.

So i thought to combine the 'websocket_chat.c' sample with my BLE peripheral. I setup the websocket server after the 'connect' event so that i only have a webserver running when i have an actual paired device. I need to split the 'main' method into several other functions.

What i've done now is moved this part

struct mg_mgr mgr;
struct mg_connection *nc;

Outside main and defined them as static variables in my C file. Then i commented out the signal handlers (can i do this safely), because i want to 'tear down' the websocket server once i get a disconnect from the Bluetooth stack. In that function i set the signal_received to 1 and call mg_mgr_free(&mgr);

Would that work? Off course i still be using this code in main:

while (s_signal_received == 0) {
mg_mgr_poll(&mgr, 200);
}

Sign In or Register to comment.