This may be a little premature given that ESP32 OpenESP32 development is still in progress (at the time of posting). But I was too excited to find a device I ordered, and was just delivered, before the ESP news came out has an ESP-C2 module inside. The hope is that this device look-over will end with a working switch running OpenESP32C2.
It's a non-Tuya HomeKit 10A breaker/switch in a standard white casing. Model BSD16.
and inside
The module is a DOIT ESP-C2-02 N2. I think N2 means it has 2Mb flash.
Before I unsolder or solder up too much, in case the ESP is locked and I cannot flash it (and so it can go into the resale pile), I attached 3.3v and ground and used a sewing needle on TX to capture the UART log (74880 baud).
Code: Text
Log in, to see the code
So it's a Cozylife device, also evidenced by the logo in the QR code in the manual. No mention of Secure Boot or encrypted flash.
Proceeding to solder RX/TX and using a pogo pin to ground BOOT pad to pull it low and into flash download mode:
Flash success. After a power-cycle with BOOT/GPIO9 disconnected from ground, the OpenESP32C2 AP can be seen broadcasting
Connecting to the AP causes a brownout reboot though, so I guess I'm not feeding it enough power, despite it being connected to an external PSU that should be able to give it <5A.
and powered from the mains the device does not brownout when AP is joined.
I went through each GPIO pulling all those available on the module high - 4, 5, 6, 7, 10, 18, 19, 20 but they had no effect. Taking the unit apart again it seems the button is GPIO5 and the LED is GPIO7. The button always seems to have continuity with GPIO5, pressed or not. I've not found the GPIO for the relay.
The main GUI is responsive, but I am finding I need to power-cycle the unit quite a lot. The logs sometimes come through and sometimes nothing shows for a while.
lots of malloc errors appear sometimes.
Code: Text
Log in, to see the code
With the button set and after a quick push, these will sometimes show in the logs
Code: Text
Log in, to see the code
I might flash original firmware back to be sure all works as expected.
Very interesting experiments, I wonder if there is OTA possiblity for this platform, or is it too secured? I mean, before flashing via UART.
The decreasing amount of free 22804 memory usually means that something is blocking TCP sockets of HTTP server and they don't free HTTP buffer. It's an unexpected behaviour of LWIP. Maybe we can fix it by adjusting some LWIP settings, like a socket timeout, etc, I don't know, just speculating at the moment. @insmod might have some ideas. Does it happen only on this ESP module or on others as well?
hmm. untouched, the free memory slowly decreases towards unresponsiveness. the device seems to be staying up, but there are periods where it is unresponsive. When it comes back it'll splurge a load of mallocs into the log.
Code: Text
Log in, to see the code
Added after 40 [minutes]:
p.kaczmarek2 wrote:
I wonder if there is OTA possiblity for this platform, or is it too secured
still responsive.
and I just thought to try PWM on for the LED instead of LED and that works.
It does oddly flickery when 'off' though. Still, feels like progress.
Added after 24 [minutes]:
and it turns out the relay is on IO4 and is also PWM. I guess the frequency needs determining as with 4:PWM:2 it'll click on and off when switched to on
Added after 1 [hours] 27 [minutes]:
There's a BP2525 (bottom middle) and there appears to be continuity from at least 2 of the legs to the D3 side of the T4 component, the other side of which is connected to the leg of the relay in that corner. Not sure what this means for an OBK config at this point though.
LED, and to some extent the relay, are better with 1344_merge_be604adfa333 where I see some PWM/pin changes have been made. Currently LED does not flicker when off and is solid when on. Relay are both a bit hit-and-miss triggering on, but maybe this is down to the unknown PWM frequency needed for either.
relay, button, LED all work as normal. I didn't mention that I'd hooked up a logic analyser to LED and relay contacts and there was no sign of PWM, so this makes sense.
Added after 2 [hours] 53 [minutes]:
unless there are other, yet to be identified, issues this could be considered a complete conversion to OpenESP32C2. In which case the template would be
Seems fast and stable in all the testing above since malloc issue was sorted. I've not left it online for any longer than a day but I'll leave it plugged in to be sure it's happy for days/weeks
>>21229886 The system itself runs stable.
Problems:
I2C not working on some pins (most important - i wasn't able to get bp5758d on wroom-07 module working)
UART receiving (on C6 if connected to RX pin - works okay, on C2 soldered to tuyamcu battery pir sensor - receives nothing). Sending works ok.
OTA can be very slow, up to 3-4 minutes. Restart before OTA is recommended.
PWM was flickering heavily on C2, cause unknown. But, i believe it is solved when timer clk_cfg started using SOC_MOD_CLK_RC_FAST instead of LEDC_AUTO_CLK.
No static ip.
When using powersave dynamic frequency, if entered freq is wrong - esp-idf driver will print it to uart only - so we won't know that custom frequency wasn't applied. Also, when max freq value is too low (like 40mhz on C3), wifi will disconnect and won't be able to reconnect.
No pindeepsleep.
BL0937 gpio isr is not implemented.
Those are off the top of my head, some other issues may also be present.
For I2C - perhaps because Soft_I2C_SetHigh calls for HAL_PIN_Setup_Input_Pullup, instead of HAL_PIN_SetOutputValue(pin, 1)?
The discussion revolves around the BSD16 HomeKit 10A breaker switch, which incorporates a DOIT ESP-C2-02 N2 module. The user is experimenting with the device to run OpenESP32C2 firmware. Initial tests revealed issues with GPIO functionality, particularly with the button and LED connections. Users reported memory management problems, including malloc errors and unresponsiveness, which were addressed through firmware optimizations. The relay and LED behavior improved after adjustments to PWM settings. The device is now considered stable for use, with successful integration into the OpenESP32C2 environment, although some issues with I2C and OTA performance remain. The final configuration includes specific GPIO assignments for the relay, button, and LED. Summary generated by the language model.