Could this be ported to the SparkCore?
This would let us be able to simulate a lifx bulb.
Could this be ported to the SparkCore?
This would let us be able to simulate a lifx bulb.
I have done the porting and fixed 1 error that is in the old library.
However, the random()
function has only been added recently and we might need to wait for a while before it’s on the online compiler.
If you want to test it locally, i can fork the original repo and push the updates.
I won’t call it porting since all i did was to copy and paste, check for all the errors and fix them.
Update
i placed the random()
functions in the library and tested. Now it compiles fine!
So i consider the “porting” done.
thats awesome! … thank you. I would love to see the code.
Alright im out right now though. Will post in github later for your usage.
Having some compilation issues which i can’t figure out with my understanding of pointers etc.
If someone can help with the porting: i have done it halfway here:
https://dl.dropboxusercontent.com/u/36134145/lifx.zip
1.) It’s almost there but some functions are not properly defined and giving compilation errors
2.) lowByte and highByte are unique to Arduino and requires a change to the Spark format.
3.) A few more functions have not been ported yet as i attempt to fix the error for processRequest()
Ping @bko @peekay123 @mdma
Hi Kenneth, I’ll take a look for you.
EDIT: I built a project in the online IDE.
First, add
#pragma SPARK_NO_PREPROCESSOR
#include "application.h"
to the top of the ino file. This will clear up some of the strange compiler warnings.
Then setLight()
was not found. I couldn’t find it in any of the sources.
If we’re going to collaborate, it might be best we create a shared online IDE account so we can work on the files together - simpler than copying and pasting changes between us!
@kennethlimcp, the macros for lowByte and highByte is:
#define lowByte(w) ((uint8_t)((w) & 0xFF))
#define highByte(w) ((uint8_t)((w) >> 8))
@mdma, setLight() is in arduinolifx.ino
My goodness, how did I miss that? Thanks! But more importantly, why does the compiler miss it? Ah, I need a forward declaration for the function.
When I add that, it compiles more but barfs out calling processRequest
and handleRequest
, and I don't find these....unless they are hiding in plain sight again.
Kenneth, is all the library source available? When I'm porting, I usually copy all of the original source over to the source files for the port. Anything that is really difficult, I just comment out with #if 0 / #endif and leave until later. You can then always have the library compile then slowly uncomment some code, make it compile, repeat and rinse!
Yes they are all available. I took the approach you mentioned and commented some code to compile first.
Just 3 functions left to complete the port.
I placed the unported functions in another file so you should be able to locate it.
Update
After some good sleep, there’s now progress!
I just need to fix these errors:
In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:29,
from RGBMoodLifx.h:16,
from RGBMoodLifx.cpp:1:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
arduinolifx.cpp:1:0: warning: ignoring #pragma SPARK_NO_PREPROCESSOR [-Wunknown-pragmas]
#pragma SPARK_NO_PREPROCESSOR
^
In file included from ../inc/spark_wiring.h:30:0,
from ../inc/application.h:29,
from arduinolifx.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
arduinolifx.cpp: In function 'void setup()':
arduinolifx.cpp:133:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbLabelLength; i++) {
^
arduinolifx.cpp:146:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbTagsLength; i++) {
^
arduinolifx.cpp:159:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbTagLabelsLength; i++) {
^
arduinolifx.cpp:181:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbLabelLength; i++) {
^
arduinolifx.cpp:185:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbTagsLength; i++) {
^
arduinolifx.cpp:189:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbTagLabelsLength; i++) {
^
arduinolifx.cpp: In function 'void loop()':
arduinolifx.cpp:231:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxPacketSize; i++) {
^
arduinolifx.cpp: In function 'void handleRequest(LifxPacket&)':
arduinolifx.cpp:384:50: error: 'word' was not declared in this scope
hue = word(request.data[2], request.data[1]);
^
arduinolifx.cpp:468:61: error: 'word' was not declared in this scope
power_status = word(request.data[1], request.data[0]);
^
arduinolifx.cpp:492:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbLabelLength; i++) {
^
arduinolifx.cpp:515:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbTagsLength; i++) {
^
arduinolifx.cpp:538:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < LifxBulbTagLabelsLength; i++) {
^
arduinolifx.cpp: In function 'unsigned int sendUDPPacket(LifxPacket&)':
arduinolifx.cpp:603:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < sizeof(mac); i++) {
^
arduinolifx.cpp:612:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < sizeof(site_mac); i++) {
^
arduinolifx.cpp: In function 'unsigned int sendTCPPacket(LifxPacket&)':
arduinolifx.cpp:675:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < sizeof(mac); i++) {
^
arduinolifx.cpp:684:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < sizeof(site_mac); i++) {
^
arduinolifx.cpp: In function 'void printLifxPacket(LifxPacket&)':
arduinolifx.cpp:745:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < sizeof(mac); i++) {
^
arduinolifx.cpp:757:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < sizeof(site_mac); i++) {
^
In file included from arduinolifx.cpp:40:0:
color.h: At global scope:
color.h:58:5: warning: 'rgb hsv2rgb(hsv)' defined but not used [-Wunused-function]
rgb hsv2rgb(hsv in)
^
make: *** [arduinolifx.o] Error 1
Compile failed - compile failed
Should word()
be changed to u16int_t
?
Here’s the code that compiles. There was also the word
macro that combines two bytes into a 16-bit word.
The code is on github. Let me know when you’ve forked it and I’ll delete the repo.
You were so close! There wasn’t much left to do, apart from the lowByte/highByte/word defines and sorting out the order of function declarations.
I’ll test it out in a while. Seems like you have the last bit required!
Will port and give credit to @mdma and @peekay123
@lightx, the port is done and available at: https://github.com/kennethlimcp/arduinolifx
@mdma, you can delete the repo now. Thanks!
@peekay123, i am trying to get this into the libraries but it’s giving me compilation errors for the invalid file path. You should be fairly familiarly with this:
The repo is at: https://github.com/kennethlimcp/arduinolifx
Great, thanks everyone!
I tried it and its not working. I put the debug = 1 and connect via spark-cli to monitor it and its not showing anything. Ive also tried using screen /dev/cu.usb* 38400 and nothing.
The only thing i’ve changed is the name of the bulb, the mac address and also the pins for the red/green/blue to A4, A5 and A6 (I didn’t plug anything into it yet)
When I initially turn it on after a few second it automatically reset itself (crash?). Its fine after but nothing happens. Can’t connect to the serial. It sometimes get stock in the very fast cyan light flashing. I reset it and its fine. The only way to stop this is if I flash another firmware.
??
PS: I did try the arduino original code with an arduino and it does work. Its still showing in the LIFX iOS app.
I don’t have the hardware and it’s going to be hard to determine the issue. But code wise, they should be compatible already.
Let me flash to my core and see how it goes. How did you compile it? Spark IDE?
Yep, online.
The only thing you need is the LIFX app and the SparkCore.
It works fine on my side:
LIFX bulb emulator for Arduino starting up...
IP address for this bulb: 192.168.43.239
Config does not exist in EEPROM, writing...
Done writing EEPROM config.
EEPROM dump:
65 114 100 117 105 110 111 32 66 117 108 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
Set light - hue: 0, sat: 0, bri: 65535, kel: 2000, power: 65535 (on)
I used the Spark-cli
to compile though. Since there are many dependencies and i don’t want to copy and paste to the Spark IDE
I’m trying to make it into a library so that it’s easier for you it’s not working yet.
How did you add all the files to the Spark IDE?
online? Let me try a completely new app and see where it leads me.
You need to copy ALL the files and make sure the .extension
are all correct.
All the files are here:
Also, add this line:
Serial.begin(38400);
while(!Serial.available()) Spark.process();
It will wait for you to press a button on the keyboard before running the code.
im not sure what I’m doing wrong but its not letting me see the serial. Ive copy/paste all the files correctly and made sure its the right extensions and added the line you mention.
— EDIT
I saw it and the output is
LIFX bulb emulator for Arduino starting up...
IP address for this bulb: 0.0.0.0
Config does not exist in EEPROM, writing...
Done writing EEPROM config.
EEPROM dump:
82 111 115 101 32 66 117 108 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
Set light - hue: 0, sat: 0, bri: 65535, kel: 2000, power: 65535 (on)
Why am I not connected to the wifi but Im breathing cyan correctly!?
What do you mean by that?
If you have sent Wifi credentials to the core before, i will connect to the Wifi network before running user code.