Need help with child process NodeJS with Python

Details :
• Raspberry Pi Zero W (using over Wifi)
• Android OnePlus2 OxygenOS v3.6.1
• LED Strip: WS2811
• Blynk Server
• Sparkfun’s Cloud Clouds Project:

I’ve been working on a personal project where I basically recreate Sparkfun’s Cloud Clouds Project (link above) but using just a Raspberry Pi Zero W, and while doing this I ran into a problem. There are 3 Modes on this project Mode 3 which is activated by turning Button 3 on turns the LED Strip to weather mode where it takes in data from OpenWeatherMap API and then turns the LEDs a certain color that matches that specific weather. Mode 2 which is activated by pressing Button 2 turns the LEDs to a certain color based on the time of day. Mode 1 which is activated by turning Button 1 on turns the LEDs to a user specified color that is provided to the program via the zeRGBa Widget on the app. I haven’t yet linked the code for Modes 2 and 3 to the JS file that actually processes the Blynk commands that are sent from my phone but I’m in the process of doing that. Below I have put the code for the Java Script File that first checks to see if Button 1 is on and then turn on an indicator LED and changes the display to read: “RGB Mode Activated”. Then it listens for commands from the zeRGBa widget, once the widget sends a color it takes the colors and then creates a child process that executes a Python script that actually controls the LED Strip (the python code is below as well). Once it enters the python script the python script stores the red green and blue values in variables which it then uses to turn the LED Strip to the color specified by the zeRGBa Widget. Since the python script takes a long time to start the LED Strip I put a while loop that continuously checks for different colors of the zeRGBa and also checks to see if the button is on or off using the Restful API. Once the python script sees that the button is turned off it exits the while loop and sends a message to the JavaScript program saying it is ‘finished’. Then once the JavaScript file sees that the python script has sent back ‘finished’ it kills the child process and resets to the very beginning once the button is pressed again. This is how it is supposed to run but I cant get the child process to end, for some reason it just stays running even if the button is off, I even put the zeRGBa listener inside the if (button == ‘1’) so that it is only running while that button is on, but it is running even if the button is off. I don’t have much knowledge on child processes so that’s probably my code isn’t working so if someone could look at my code and edit it/ guide me in the right direction I would be very thankful. If you have any questions let me know.

Thanks in advance!

JavaScript Code (fileName: blynkCustom.js):

const Blynk = require('blynk-library');


const blynk = new Blynk.Blynk(AUTH, options = {
    connector : new Blynk.TcpClient()

// Set up Virtual Pins
const BlynkButton1 = new blynk.VirtualPin(1); // button that activates custom RGB mode
const BlynkLED1 = new blynk.virtualPin(2); // LED that indicates custom RGB mode is on
const lcd = new blynk.WidgetLCD(0); // LCD that displays information
const zeRGBa = new blynk.virtualPin(7); // zeRGBa that send RGB data through pin 7

BlynkButton1.on('write', function (status1)
    if (status1 == 1)
        blynk.virtualWrite(2, 255); // turn on indicator LED (BlynkLED1) to signify that the button is pressed
        lcd.print(0, 0, 'Custom RGB Mode ON!'); // print message to LED to signify button is pressed
        zeRGBa.on('write', function (param)
            if (status == 1) // this if statement should only execute if and on if BlynkButton1 is in on mode and zeRBa sent data
                // set up colors
                var red = param[0];
                var green = param[1];
                var blue = param[2];
                // send colors to console

                // start child process (should only start if and only if BlynkButton1 is in on mode and zeRBa sent data)

                const spawn = require('child_process').spawn;
                var pythonProcess = spawn('python', ["/path/of/python/file/", red, green, blue]);
                // python sends a message back if finished
                pythonProcess.stdout.on('data', function (data)
                    if(data[0] == 'finished') // if python returns 'finished' then kill the child process
                        console.log("Python Message: " + data[0]);
        blynk.virtualWrite(2, 0); // turn off indicator LED (BlynkLED1) if button is not pushed
        lcd.clear(); // clear lcd if button not pushed

Python Code (fileName:

import sys
import time
import requests
from neopixel import *

# get colors from the child process call
red = int(sys.argv[1]);
green = int(sys.argv[2]);
blue = int(sys.argv[3]);

LEDCount = 60;
LEDPin = 18;
LEDFreq = 800000;
LEDInvert = False;
LEDBrightness = 255;
LEDChannel = 0

# Create neopixel object
strip = Adafruit_NeoPixel(LEDCount, LEDPin, LEDFreq, LEDDMA, LEDInvert, LEDBrightness, LEDChannel);
# Initialize library

# flash Red Green and Blue to signify that RGB mode has been entered succesfully

for i in range(strip.numPixels()):
    strip.setPixelColor(i, Color(255, 0, 0));;


for i in range(strip.numPixels()):
    strip.setPixelColor(i, Color(0, 255, 0));;


for i in range(strip.numPixels()):
    strip.setPixelColor(i, Color(0, 0, 255));;


# this script takes a long time to actually start up but once in script LEDs are update almost instantly
# that is why i have put a while loop in here so it updates in real time. but once the loop has ended it should return 
# 'finished' back to the parent which then kills this child script so that it wont run

v1StatusLink = ''; # use restful api to check the status of the button (BlynkButton1)
v7StatusLink = ''; # link for zeRGBa status
v1json = requests.get(v1StatusLink).json() # json obj
v1Status = v1json[0]; # current status of button (BlynkButton1)

while v1Status == '1': # while loop executes only when button (BlynkButton) is on
    v7json = requests.get(v7StatusLink).json(); # realtime colors without delay
    red = int(v7json[0]);                       #         |
    green = int(v7json[0]);                     #         |
    blue = int(v7json[0]);                      #         V

    # update strip
    for i in range(strip.numPixels()):
        strip.setPixelColor(i, Color(red, green, blue));;

    # check to see if the status of button (BlynkButton1) has changed
    v1json = requests.get(v1StatusLink).json();
    v1Status = v1json[0];

# once the button is turned off exit loop and send 'finished' back to js file so that it can kill 
# child process