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
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