Network RGB lighting

Hey guys how’s it going. I am in need of some help. So I came across these lights called “network RGB lights” on youtube. I thought they are super cool here is a link explaining it https://www.youtube.com/watch?v=2ipOOAOfAk8
This he has his code on an instructables Networked RGB Wi-Fi Decorative Touch Lights

however this instructable is about 2 years old. he has working examples and he has all the code and wonderful instructions however the problem is. Since it has been released Spark io has changed to particle photons. with that it changed their IDE and all their other items. the code is based on the old IDE and I am having trouble converting it over.

I know this is not an electrical engineering website so ill spare you most of the details however. I hooked up everything flashed it and changed the code/errrors it was yelling at. Now when I touch the light. The server side code errors out giving error as

./filimin.sh: line 50: [: 1"40003400053038","last_app": integer expression expected
./filimin.sh: line 54: "40003400138333038","last_app": syntax error: operand expected (error token is ""400034000138333038","last_app"")

attached is my updated code for each spark/particle io
the only things I changed where the include of the neopixel library I put the latest one in there as the old one errored out. I can confirm this neopixel library works with no problem as I can change the colors on it so I dont think its the problem
the other things I changed in this code are anywhere it says “particle.*” for example “Particle.function” instead of spark.function because as I said, spark IDE changed.
This now flashes fine with no errors.
i had to attach it via pastebin because i am over 20k characters :frowning:
network rgb - Pastebin.com

my guess as to what happened is particle devs updated a function that now has more requirements and one of the functions in here does not meet that and is erroring out with the above and “last_app”

Now for the server code that I run i added the same token and spark id’s please note those aren’t valid id’s i removed mine as i don’t want to show them.
When I turn both of the particles on and then start the server it errors out with the first error I noted.
The server only errors out if I have the particles plugged in if not it will continue on like it was working properly. This was leads me to believe something is wrong in the particle code because as soon as I turn it on it makes a call to the server (or something like that ) and then errors out
I have looked into both of these errors and can’t really find much on it “last_app” refers to a IDE call. The others I honestly have a clue because I can’t find what it is referencing

any help would be appreciated even lead me in the right direction



#!/bin/bash
token='PUT_YOUR_TOKEN_HERE'
sparkID[1]='UID OF SPARK 1'
sparkID[2]='UID OF SPARK 2'

sparkResponses=/tmp/sparkVals
watchdogFile="/tmp/scriptWatchdog"
logFile="/var/log/lampServer"
pollSpeed=0.2

# INITIALIZATION
if [[ ! -p $sparkResponses ]]; then
    echo "$(date +"%Y%b%d %r") -  no pipe found at init: creating pipe" >> $logFile
    mkfifo $sparkResponses
fi
trap "rm -f $sparkResponses" EXIT
exec 3<> $sparkResponses
numOfSparks=${#sparkID[@]}
for i in `seq 1 $numOfSparks`;
do
    sparkPID[i]='999999999'
done
lampState='0';
lastLampState='0'

# RUN
while true
do
    touch $watchdogFile
    for i in `seq 1 $numOfSparks`
    do        # the pipe disappears sometimes...dunno why. wat?
        if [[ ! -p $sparkResponses ]]; then
	    echo "$(date +"%Y%b%d %r") -  Error: no pipe found. Creating pipe" >> $logFile
            mkfifo $sparkResponses
        fi
        deviceId=$((lampState >> 10))
        cmd=$((lampState >> 8 & 3))
        color=$((lampState & 255))
        if ! ps -p ${sparkPID[i]} > /dev/null
        then
            echo "Sending cmd: $cmd color: $color from Spark $deviceId to Spark $i PID"
            curl -N --max-time 2 -s https://api.spark.io/v1/devices/${sparkID[i]}/poll -d access_token=$token -d "args=$lampState" | grep return | cut -d ":" -f 2 | cut -d " " -f 2 >&3 &
            sparkPID[i]=$!
        fi
    done
    lampState=""
    while [[ -z "$lampState" ]]
    do
        if read -t 0.01 lampState <$sparkResponses
        then
            if [ "1$lampState" -eq "10" ]
            then
                lampState=$lastLampState
            fi
	    if 	[ "$((lampState >> 10))" -eq "0" ]
	    then
		echo "*********** ERRONEOUS DATA **************"
	    fi
            if [ "`expr $lampState % 1024 `" != "`expr $lastLampState % 1024`" ] &&
		[ "$((lampState >> 10))" -gt "0" ]
            then
                # echo "lamp state has changed to $lampState. Destroying all life forms."
		deviceId=$((lampState >> 10))
		cmd=$((lampState >> 8 & 3))
		color=$((lampState & 255))
		echo "$(date +"%Y%b%d %r") -  Received state: $lampState cmd: $cmd color: $color from Spark $deviceId." >> $logFile
		echo "Received state: $lampState cmd: $cmd color: $color from Spark $deviceId."
                for i in `seq 1 $numOfSparks`
                do
                    kill ${sparkPID[i]}
                done
                herrGarbage="nothing"
                while [ -n "$herrGarbage" ]
                do
                    read -t 0.01 herrGarbage <$sparkResponses
                    if [ -n "$herrGarbage" ]
                    then
                        #echo "emptying queue: $herrGarbage"
			deviceId=$((herrGarbage >> 10))
			cmd=$((herrGarbage >> 8 & 3))
			color=$((herrGarbage & 255))
			echo "$(date +"%Y%b%d %r") Dumping state: $herrGarbage cmd: $cmd color: $color from Spark $deviceId." >> $logFile
			echo "Dumping state: $herrGarbage cmd: $cmd color: $color from Spark $deviceId."
                    fi
                done
                lastLampState=$lampState
            else
                lampState=""
            fi
        else
            lampState=$lastLampState
        fi
    done
    sleep $pollSpeed
done

You may also want to change the API addresses for https://api.particle.io/v1/...

You can also test the firmware with one of these sites to see whether the Particle.function()s work as expected
http://jordymoors.nl/interface/
http://suda.github.io/particle-web-interface/

But you have double checked that they are valid? Just because the device IDs in your pastbin are not correct length (they have to be same length : 24 HEX digits, lowercase)

1 Like

LOL well… I knew I would miss something dumb like that! good catch I really appreciate it. I will change that when I get home. this may just fix it! as it now makes sense trying to call a function and it erroring out on “last_app”

didn’t know about those websites I will give them a try. Thanks

Yes I have double checked them, originally actually had trouble with c and p the scripts which caused a ton of errors. I then just downloaded them and scp’d them over to my pi so nothing would get messed up.
and you’re right they are different lengths in the example I just randomly typed numbers in there just as an example :slight_smile:

1 Like

sooo ive been doing some diag and unfortunately changing it didn’t help but you put me on the right track, even though i still need help. So it looks like the curl in the server is not able to parse some bits but i dont know why. I manually cobbled together a sort of link myself by putting the bits together here is the curl

Also the links you gave me are great however they don’t help much at least for this project. I think they will be good in the future but i never see anything pass from the devices except when i disconnect and reconnect it :frowning:

curl -N --max-time 2 -s https://api.particle.io/v1/devices/400034000547343138333038/poll -d access_token=$token -d "args=$lampState" | grep return | cut -d ":" $
            sparkPID[i]=$!

here is what i cobbled together (i changed the device id and token)

https://api.particle.io/v1/devices/4002343242300547343138333038/tBaseline/?access_token=355ac7a4asdf7b9538f29fb377b80f46fc30

here is what i get when it is returned

{"cmd":"VarReturn","name":"tBaseline","error":null,"result":2069.442138671875,"coreInfo":{"last_app":"","last_heard":"2017-01-25T20:47:07.415Z","connected":true,"last_handshake_at":"2017-01-25T20:16:54.037Z","deviceID":"400034002343243138333038","product_id":6}}

i now see where its getting the “last_app” from when it returns an error.
however i dont know where to go from here
because there is a particle function “poll” with these variables but i added each one of those to link but it seem to change nothing even though when i add “poll” it just says no variable found. any suggestions?

Particle.function(“poll”, pollLamp);
Particle.variable(“tDelay”, &tDelayExternal, DOUBLE);
Particle.variable(“tBaseline”, &tBaselineExternal, DOUBLE);

Try the moder version

  Particle.variable("tDelay", tDelayExternal);
  Particle.variable("tBaseline", tBaselineExternal);

I don’t know if the old version is still part of the test program and hence it could have died a quiet death :wink:

Although the response seems to indicate your value does arrive.

But maybe you could also tag the original contributors of that project whether they’ve got some updated code.

i have switched these however it looks by the output that there is a variable poll which you should be able to query and that does most of the work but when i do it says variable not found :frowning:

{"id":"400088888888888","name":"RGB 1","last_app":null,"last_ip_address":"88888,"last_heard":"2017-01-25T21:35:01.950Z","product_id":6,"connected":true,"platform_id":6,"cellular":false,"status":"normal","current_build_target":"0.6.0","default_build_target":"0.6.0","variables":{"tDelay":"double","tBaseline":"double"},"functions":["poll"],"cc3000_patch_version":"wl0: Nov  7 2014 16:03:45 version 5.90.230.12 FWID 01-a297ce59"}

yeah i sent him a message on hackster and instructbles maybe he will eventually reply. but from my research of what he did was he created a 2nd version running completely off an esp8266 using mqtt. which honestly i’d like better but he his selling that version so I would assume he wouldn’t be giving that code out. however I have thought about purchasing one. then extracting the firmware off the esp module then burning it into my own as I run home automation which relies heavily on esp modules

i will continue to bash on, im slowly getting there… i think

This is not a Particle.variable() but a Particle.function() which gets called via a POST request, while variables get retrieved via a GET request.

sorry you’re right, thats just my lack of knowledge showing on what is what in here :stuck_out_tongue:

well after tons of googling I still haven’t figured it out, however I have found an updated project here FamiLamp: Cloud-Synchronized Color-Selectable Lamps
still uses the photon and has better functions .
just updating this thread as I won’t be diag’ing the code anymore and I am sure some other poor sap will come along searching the same thing an updated project on google and not finding anything for days. So follow the link the project is still on going
glhf

1 Like