today I’d like to show you how I modded an ordinary lamp into a smart (IoT) one.
Foreword
I’m a huge Rocketbeans TV Fan. Rocketbeans is a big 24/7 Stream Show focused on gaming. Germans may know the hosts from “Giga” or “Game One”.
As they started selling a USB Lamp with their logo and some RGB-LED I thought about making it smart to display the current type of show running. At the moment there are three types of shows available: “Live”(=Red), “Premiere”(=Blue), “Playback”(=White). The unmodified lamp is able to switch colors on a button press.
I bought one of them. As soon as it arrived I started to disassemble the lamp to check the circuit board. To my surprise, it’s straight forward.
The (smart) Microcontroller
Leroy told me about the ESP32 which is a very small Microcontroller with built-in Wifi and Bluetooth. This one seems to be a perfect match for the smart part of the lamp.
After viewing and manually scraping their Website I was able to find a Link which returns the current and four further shows as JSON object. (The following image only shows the current show also referred as Array[0]).
Now we gathered all requirements and start tinkering.
Reverse Engineering the Lamp Circuit
We started to measure some circuits and figured out how the embedded controller works. The controller has eight pins: GND, 5v, a Touch Button on the Case and three colors. The remaining ones may be used for infrared.
Next we removed the embedded microcontroller to attach the ESP32 controller.
Writing the Microcontroller Code
Since I never wrote any kind of ESP32 Code I decided to invest some time to read Tutorials/Blogs about “ESP32 Wifi”, “Arduino JSON” and “Arduino HTTP Client”.
Beanduino: Dynamic Color Lamp
DyCoLa1000DEV
Marvyn Zalewski <[email protected]>
(c) 2015 The Senso Team, All rights reserved.
Beanduino – Attempting to connect to Wifi network, SSID: WIFI
Beanduino – Attempting to connect to Wifi network, SSID: WIFI
Beanduino – Connected to network
Beanduino: Dynamic Color Lamp;live;red
Beanduino: Dynamic Color Lamp;live;red
Putting it all together
Now we know everything to set up the smart lamp. At first, we’re soldering all needed wires and stick them into the battery compartment.
As you can see there are six wires coming from the Lamp Circuit. (VCC which is 5V, GND, directly from the Button and all three colors.)
Due to space issues, we soldered the wires directly onto the ESP32.
Wire Map:
ESP32 VIN -> Lamp Circuit VCC
ESP32 GND -> Lamp Circuit GND
ESP32 D14 -> Lamp Circuit LED Green (the left resistor R5)
ESP32 D22 -> Lamp Case Button (without any function at the moment)
ESP32 D26 -> Lamp Circuit LED Blue (the middle resistor R6)
ESP32 D33 -> Lamp Circuit LED Red (the right resistor R7)
After a nearly whole code refactoring, I finished it and moved it to Github.
Beanlamp Code
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
/*
* Coniguration
** CONNECTION_INDICATOR - blinking led during startup when defined
*/
#define CONNECTION_INDICATOR
#define LED_RED GPIO_NUM_14
#define LED_GREEN GPIO_NUM_27
#define LED_BLUE GPIO_NUM_26
#define WIFI_SSID "WLAN"
#define WIFI_PASSWORD "WLAN_PASSWORD"
#define ROCKETBEANS_API "https://www.rocketbeans.tv/?next5Shows=true"
/*
* Information
*/
#define __product__ "Beanlight"
#define __version__ "1000DEV"
#define __author__ "Marvyn Zalewski <[email protected]>"
#define __copyright__ "(c) 2018 KeyboardInterrupt.org"
/*
* Global Variables
*/
int status = WL_IDLE_STATUS;
/*
* Functions
*/
void setLampToRed()
{
digitalWrite(LED_RED, HIGH);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, LOW);
}
void setLampToBlue()
{
digitalWrite(LED_BLUE, HIGH);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_RED, LOW);
}
void setLampToGreen()
{
digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_BLUE, LOW);
digitalWrite(LED_RED, LOW);
}
void setLampToWhite()
{
digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_BLUE, HIGH);
digitalWrite(LED_RED, HIGH);
}
void setLampToBlack()
{
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, LOW);
digitalWrite(LED_RED, LOW);
}
/*
* Init
*/
void setup()
{
Serial.begin(115200);
Serial.println(__product__);
Serial.println(__version__);
Serial.println(__author__);
Serial.println((String)__copyright__ + "\n");
pinMode(LED_RED, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
while (status != WL_CONNECTED)
{
Serial.println((String)__product__ + " attempting to connect to Wifi network, WIFI_SSID: " + (String)WIFI_SSID);
status = WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#ifdef CONNECTION_INDICATOR
setLampToRed();
delay(2000);
setLampToBlue();
delay(2000);
setLampToGreen();
delay(2000);
#else
delay(6000);
#endif
};
#ifdef CONNECTION_INDICATOR
for (int i = 0; i <= 3; i++)
{
setLampToGreen();
delay(250);
setLampToBlack();
delay(250);
};
#endif
Serial.println((String)__product__ + " connected to network");
}
void loop()
{
if ((WiFi.status() == WL_CONNECTED))
{
HTTPClient http;
http.begin(ROCKETBEANS_API);
int httpCode = http.GET();
if (httpCode > 0)
{
const size_t bufferSize = JSON_ARRAY_SIZE(5) + 5 * JSON_OBJECT_SIZE(14) + 2970;
DynamicJsonBuffer jsonBuffer(bufferSize);
String payload = http.getString();
JsonArray &root = jsonBuffer.parseArray(payload);
if (!root.success())
{
Serial.println((String)__product__ + " parsing failed.");
Serial.println(payload);
}
/* When current show is live */
if (root[0]["isLive"] == 1)
setLampToRed();
/* When current show is new */
else if (root[0]["isNew"] == 1)
setLampToBlue();
/* When current show is playback */
else
setLampToWhite();
}
else
{
Serial.println((String)__product__ + " error on HTTP request");
}
http.end();
}
delay(60000);
}
Result
After working nearly ten hours on the project I would say it was a lot of fun.
If you have any questions or improvements, let me know in the comments. 🙂
Marvyn is a nerdy guy which is into Linux and everything connected to it. He also loves to automate his home and build up a home lab which includes e.G. a custom steam machine and backup automation.
He loves to hear EDM music and try to become a
gin enthusiast.
Building a Do-It-Yourself server rack, with old laptops as servers, airflow optimization, network and power distribution and low-noise ventilation for use in a living room while completely blending in and looking like a regular cabinet. Read more…
Hey Guys,I’d like to tell you about Multiprocessing using Python 3.7 which is slightly different that Multithreading with Python 2.7. I already wrote something about Multithreading with Python 2.7 which you can read here. Basics By Read more…
Hey guys,recently Rocketbeans updated their Website and also updated the API Endpoint for our beautiful lamp. If you haven’t read about the Smart RGB-LED Lamp before you better take a look at my older Post Read more…
This website is using Google Analytics. Please click here if you want to opt-out. Click here to opt-out.
0 Comments