Kacang Bawang

ESP8266 SDK: how to debug with gdb

Not long ago, to little fanfare, Espressif (the makers of ESP8266) released gdbstub – a library that allows use of gdb on ESP8266. It works with both non-OS and RTOS SDKs, and works over UART, not JTAG. You get 1 breakpoint for RAM and 1 breakpoint for FLASH. Is this awesome, or what!? Authorship is unattributed, but is believed to have been written by Sprite_tm.

In this post, I will show you how to add gdb support to your project. This example will use the RTOS SDK, but applies just the same to the non-OS SDK.

Read more »

Which allocation scheme does ESP8266 RTOS SDK use?

I wanted to know which memory allocation scheme (heap_1.c, heap_2.c, heap_3.c, heap_4.c or heap_5.c) was used in the ESP8266 RTOS SDK. This is not mentioned anywhere in the docs (I’ve looked as of 1/12/16). What to do?

Let’s just take a look at what is compiled in then.

Actually, this works even with a regular ‘nm’, hehe.

What do we see?

Aha! heap_4.o means heap_4.c was used. ‘T’ means that this symbol is exported.

OpenHAB2 binding architecture

In this article I will walk the reader through the inner workings of an OpenHAB2 binding. It is meant to answer the question of “who calls who and when?”, which invariably arises when one starts working with a new framework. It is a summary of what I had learned while writing the binding for my smart switch. If you are thinking about writing a custom binding from scratch, then this article is for you!

Read more »

ESP8266 512k flash: compiling using RTOS SDK 1.3

Since update from version 1.2 to 1.3 of Espressif’s RTOS SDK, if you try to compile anything targeting a 512kB flash device you get this message:

In this post I will show you how to organize and compile a project to using the RTOS SDK and how to solve the above problem. This post builds on this one, review as necessary.

Read more »

ESP8266 SDK: os_printf() prints garbage, uart_init() doesn’t work…

Espressif SDK provides a function os_printf() for printing to the debug uart. However, when used out of the box it prints garbage. What gives?

Consider a default project with the following in user_main.c.

Compile, run, what do you see? That’s right – garbage. Well, it’s not really garbage, it’s actually outputting “hello world” at the default (non standard) baud rate. Ok, easy enough – we’ll just set the baud rate using uart_init() function from the SDK! Oh, wait… that function is not defined in any header that comes with the SDK… Paging Espressif, please pick up the white courtesy telephone!

That’s ok, there’s an easier way – we will use uart_div_modify() to achieve the same result. Change the hello world to this and try again:

Much better! Hat tip to unfoundbug at this reddit thread.

Old School Methods: Transformer-less Power Supplies

If you’ve read my previous posts you may be aware that I am in the process of trying to build an electronic device in Indonesia. To this end, I’ve tried to find some local talent to help me. I’ve interviewed a couple of people affiliated with an Indonesian appliance manufacturer who has a factory nearby. Ultimately, none of the candidates were a good fit, but I did learn something new, about which I would like to tell you today.

It turns out that it is possible to transform 110/220 VAC to 5 VDC really, really cheaply and without the use of a transformer. Don’t get too excited though – this method is more of a clever hack and is rather unsafe. It is presented here for educational purposes only.

Read more »

OpenWrt – Reduce Hostapd Verbosity

A quick note about how to reduce the log level of hostapd, as it tends to dominate log entries in /var/log/messages.

Read more »

Review of Fosc-21 (Focus Oscilloscopes) – a $20 USB Oscilloscope from ebay

Fosc-21 usb oscilloscope

Sometimes we make a bad spontaneous purchase. It must have happened to everyone at least once. This is the story of one such purchase.

Without doing my research I clicked ‘buy’ on a really cheap Chinese USB oscilloscope from ebay – Focus Oscilloscopes 21 (Fosc-21). The crappy-ness of this “oscilloscope” is matched only by its “software”. Instead of kicking myself, I decided to extract the maximum good that can possibly be extracted from this experience by writing a “review”. Hopefully, some poor soul about to buy this atrocity will find this post first.

Read more »

Say Bye to Provider’s DNS Servers – Be Your Own DNS Resolver

Have you ever wanted to NOT use your provider’s DNS services? Maybe they are engaged in censorship, or are modifying non-existent domains to point at pages full of advertisement? One popular solution is to use public DNS servers, such as Google’s. But ask yourself this – how much information are you giving up to a DNS server? Every time you visit a new web page, the DNS server will know about it. You can build a pretty nifty profile on a person using just that info. Well, how else would you do it? You’ve got to ask somebody for the IP address. Actually there is a better way – ask the source, and avoid the middlemen.

In this article I will show you how to set up your OpenWrt router to do its own DNS resolution. We will look up domains starting from root DNS servers, without the use of 3rd parties such as provider/Google/OpenDNS.

Read more »

My Smart Switch, or How I Built a Smarthome Gadget with No Electronics Experience, While Living in a Village in Indonesia

smart switch

They say that laziness is the mother of progress. It certainly was in my case. I am currently residing in Indonesia, where the outside lighting of one’s house is somewhat of a security practice, and it so happened that it became my job to ensure that these lights went on every evening, and equally importantly, off every morning. This involved making a trip around the perimeter of the house each evening and flipping all the light switches I came across. It is especially hard to remember to do this in the morning, because the sunlight makes it is hard to see that the lights are on. Sure enough, after about a week I no longer saw the joy in this daily routine and decided to do something about it. I was going to make a remote-controlled switch that would automate this task, and at the same time, become the foundation of a smart home installation I’ve been dreaming about. There was only one little problem – I knew absolutely nothing about designing electronics and PCBs.

In the title picture you can see the result of my efforts. The physical switch consists of two wall wells – one containing the switch itself and the other containing its “brains” (seeing how it is a smart switch and all). The virtual interface is provided by OpenHab2 running on a RaspberryPi2.

Read more »