esp8266 UDP debugging

After a lots of lots of wasted hours  debugging an I2C driver it came out that the noise from the connected cheep USB2TTL converter is way too much. Would have lost months without the help of the new DS1054z scope i’ve got.

So i came up with this – a simple UDP debugging.

Simple socket to send udp messages.

dbg

Call dbg_udp_start(0) and you are ready to go. If you prefer not to flood your LAN with debug messages broadcasts then instead of 0 provide your workstation IP address.

Them usage is as simple as:

dbg_udp(“My debug message\n”);

You can go and wrap your os_printf or whatever calls to send via UDP too.

Viewing the log is done by any netcat alike.

nc -l -u -p 20202

It’s going to be handy when the UART is talking to other devices. You can even debug your devices over the internet this way.

 

 

ESP8266 – easy interrupts

While working on a current project i’ve faced an issue with code reuse. Espressif sdk allows only one interrupt handler for all GPIOs. That’s fine for monolithic code but since we like modular code a dispatcher comes handy.

The little inconvenience i’ve had was like this. I wanted to use the drivers/key.c code but it does use the data argument , so i’ve had to modify it to use a global variable. So i can call it from my own interrupt handler. And that is ugly.

So the lab have a brand new GitHub Account – where i’ll share code.

And the remedy for the issue –  new project: esp8266_easyintr .

May need a tweek or two.  I’ve  extracted it from a wip project.

Usage:

ei_init(); // init easy interrupts
ei_attach(GPIO_NUM, GPIO_MUX, GPIO_FUNC, module_isr, module_data); // setup  handler

You can attach only one per GPIO . You will get your data at the isr and you can have a proper code separation.

 

KiCad change fields visibility utility

$ open devlog

I’ve back imported footprints for a .cmp file and I’ve misunderstood  kicad’s question about the imported footprints visibility, so all went visible.

And surprise, you can not edit visibility for all fields at once.

So  little utility was born – fixvis.

Usage is pretty simple:

./fixvis file.sch fieldid newval
fieldid:
0 - Reference
1 - Value
2 - Footprint
3 - Datasheet
4+ - custom
newval: 0000 = visible, 0001 = hidden

Example hide all footprints:

./fixvis name.sch 2 0001 > name-nofp.sch

It would be good to have a global toggle option.

$ close devlog

73!

Apache websockets with proxy_wstunnel and mosquitto

Spend last weekend trying to make apache with proxy_wstunnel to work.
The solution recommended is to add this in the apache config:

ProxyRequests off
ProxyPass /mqtt ws://127.0.0.1:8082
ProxyPassReverse /mqtt ws://127.0.0.1:8082

But no matter what it is a no go. So, where is the problem?

It’s the libwebsockets it doesn’t understand custom http headers X-… but apache adds some.

To add support for them in the file lextable-strings.h append before the blank string :

"x-forwarded-server",
"x-forwarded-for",
"x-forwarded-host",

Then do compile and install:

gcc minilex.c -o minilex && ./minilex > lextable.h
gcc minilex.c -o minilex && ./minilex > lextable.h
make && make install

Yes, do it twice. You must have a working apache2 with proxy_wstunnel module talking to mosquitto broker.

Now let’s get on the mqtt stuff.

P.S. The proper fix is to ignore all custom headers as per the HTTP specification and not consider them dangerous.