Recently on ebay i bought cheap 14$ RGB bulb with WiFi connection. They branded it as “Smart life” wifi smart bulb. It have some features, example Alexa and google home compatibility. It is so cheap, that i thought it was worth to buy and see what’s. After a couple of weeks i received it.

WiFi RGB bulb

In an external view product seems good quality. I disassembled it without turning on and found some WiFi module inside. Module is TYWE3L, In a view it reminded me esp12 module, which is module with esp8266 MCU. Then searched and found that it’s sort of esp8266 type. Then i started looking into PCB and connections. As i found everything pointed, that it is actually esp8266 module and i can program it like ordinary one. First i set up chip into flash programming mode, then connected a USB serial module to its connections. To change mode, I solder jumper wires on its pins.

For reference, you can see diagram below.

Flash and UART mode diagram

You can see diagram below, for switching between programming and serial communication modes.

Connection USB serial adapter to esp8266 module.

Module pinout

After all this setup (Like on images above), firmware programming went seamlessly. For quick test, I flashed micropython firmware and wrote small program. (To write firmware on an esp module, look up this tutorial)

Bulb code (Socket server)

import time

import network

import usocket as socket

from machine import Pin, PWM, reset

import os



# Access point, allows other WiFi clients to connect

ap = network.WLAN(network.AP_IF)



# Set WiFi access point name (formally known as ESSID) and WiFi channel

ap.config(essid='esp12', authmode=network.AUTH_WPA_WPA2_PSK,

password='esppornxx', channel=11)



# Query params one by one

print(ap.config('essid'))

print(ap.config('channel'))



print(ap.ifconfig())



HOST = '0.0.0.0'

PORT = 5555

data = '200,300,100,50'



rpwm = PWM(Pin(4, Pin.OUT))

gpwm = PWM(Pin(12, Pin.OUT))

bpwm = PWM(Pin(14, Pin.OUT))

wpwm = PWM(Pin(5, Pin.OUT))



rpwm.freq(500)

gpwm.freq(500)

bpwm.freq(500)

wpwm.freq(500)



rpwm.duty(0)

gpwm.duty(0)

bpwm.duty(0)

wpwm.duty(0)



def clearAll():

rpwm.duty(0)

gpwm.duty(0)

bpwm.duty(0)

wpwm.duty(0)



def savetofile(data):

print('open file')

f = open('color.txt', 'w')

print('write to file')

f.write(data)

f.close()



def recvok():

clearAll()

# programmed OK blink blue

delay = 0.2



for n in range(5):

bpwm.duty(1023)

time.sleep(delay)

bpwm.duty(0)

time.sleep(delay)



def socketls():

global data



print('==========')

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

#socket.settimeout(10)

sock.bind((HOST, PORT))

sock.listen(1)

while True:

conn, addr = sock.accept()

print('listenning', addr)

recv = conn.recv(2048)

if not recv:

return





print(recv)

data = recv.decode('utf-8')

savetofile(data)

recvok()

color_decode(data)

conn.sendall('Thank you!')



#conn.close()

# Soft reset

# reset()



def color_decode(data):

val = data.split(',')

rpwm.duty(int(val[0]))

gpwm.duty(int(val[1]))

bpwm.duty(int(val[2]))

wpwm.duty(int(val[3]))



def main():

try:

socketls()

except Exception as ex:

print(ex)





if 'color.txt' in os.listdir():

try:

f = open('color.txt', 'r')

data = f.read()

print(data)

color_decode(data)

main()

except Exception as ex:

print(ex)

main()



main()

This program serves as a WiFi access point. It opens 5000 port and listens with socket server.

client program sends RGB and white leds PWM data with 10 bit comma separated string, like this: “100,50,300,30”

Client code

#!/usr/bin/env python3



import socket

import sys





rgbw = sys.argv[1]



s = socket.socket()

s.connect(('192.168.4.1', 5555))

s.sendall(rgbw.encode('utf-8'))

print(s.recv(1024))

s.close()

After testing, i soldered connector in case, if I want to program another time and assembled back again.

Overall product quality for this price is fine, except that, when you set PWM to be 0, LEDs flashing very slightly, I think that problem is because, bipolar transistors which are used to drive LEDs, are not completely closed, that there is a small current leakage there. If we use MOSFETs instead, problem disappear.

If someone is interested, here is a schematics of this bulb.