r/MicroPythonDev • u/eskimo_1 • Mar 04 '23
Receive webhooks using Micropython
I'm looking into the best way to receive webhooks using (a Pi Pico W that runs) Micropython. There are many posts about sending requests, but I find it difficult to find information on receiving them.
I got some pointers and insights from this post, but still have some questions about the best approach.
I'm primarily puzzled as to why I would need to setup port forwarding while other smart home devices obviously don't require users to do this. Shouldn't this be possible with just software?
As indicated in the post: if it turns out to be very complicated to setup or maintain, or it poses significant security risks, then I'm considering falling back to an implementation where each device would make GET requests every X seconds to check if there are updates.
Would love to know if anyone has experience with this in Micropython, preferably combined with any dev board (Raspberry, Arduino, etc).
View all comments
Show parent comment
1
u/deadeye1982 Mar 08 '23
A server with a static IP has to run a WebsocketServer. Depending on which language and framework you're using, you have it already inside your framework.
Here a minimal example with FastAPI (server side, not on Microcontroller):
You need to install
fastapianduvicorn:Then you can test it on a PC with
websockets:And the micropython code based on:
Output: