Create a gist now

Instantly share code, notes, and snippets.

// ------------
// Jenkins LED
// ------------
This program will toggle two led lights. Green led at D0 will remain flashing when turned on.
It wil blink red led at D1 on and off every second.
// First, we're going to make some variables.
// This is our "shorthand" that we'll use throughout the program:
int ledgreen = D0; // Instead of writing D0 over and over again, we'll write ledgreen
int ledred = D1; //led red
bool success = true; //variable to hold whether Jenkins build scucess or not
int ledToggle(String command);
// Having declared these variables, let's move on to the setup function.
// The setup function is a standard part of any microcontroller program.
// It runs only once when the device boots up or is reset.
void setup() {
// We are going to tell our device that D0 and D1 (which we named ledgreen and ledred respectively) are going to be output
// (That means that we will be sending voltage to them, rather than monitoring voltage that comes from them)
// It's important you do this here, inside the setup() function rather than outside it or in the loop function.
pinMode(ledgreen, OUTPUT);
pinMode(ledred, OUTPUT);
Particle.function("toggle", ledToggle);
//At the setup we will light up the green led
digitalWrite(ledgreen, HIGH);
// Next we have the loop function, the other essential part of a microcontroller program.
// This routine gets repeated over and over, as quickly as possible and as many times as possible, after the setup function is called.
// Note: Code that blocks for too long (like more than 5 seconds), can make weird things happen (like dropping the network connection). The built-in delay function shown below safely interleaves required background activity, so arbitrarily long delays can safely be done if you need them.
void loop() {
//blink the red led if status is set as failed
digitalWrite(ledred, HIGH);
digitalWrite(ledred, LOW);
//Led toggle function we expose to
int ledToggle(String command) {
if (command == "red") {
digitalWrite(ledgreen, LOW);
digitalWrite(ledred, HIGH);
success = false;
return 1;
else if (command =="green") {
digitalWrite(ledgreen, HIGH);
digitalWrite(ledred, LOW);
success = true;
return 0;
return -1;
@echo off
REM We use curl command line tool to send http requests. Replace Jenkins url with the base url to jenkins
REM We query Jenkins json api to check the status of all jenkins jobs. Result is stored into a temp file
curl --silent %JENKINS_URL%api/json>c:\temp.txt
set /p string = < c:\temp.txt
REM See if word 'red' is there in the json api result.
set SubString1=red
find /c "red" c:\temp.txt
if not errorlevel 1 goto found
REM delete the temp file and call toggle function in
REM set PHOTON_DEVICE_ID and PHOTON_ACCESS_TOKEN with your photon device id and access token
REM case all green, we send argument value 'green' into the particle function
del c:\temp.txt
curl \ -d arg="green" -d access_token=%PHOTON_ACCESS_TOKEN% -k
goto :eof
echo At least one SubString was found within "%string%".
del c:\test.txt
curl \ -d arg="red" -d access_token=%PHOTON_ACCESS_TOKEN% -k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment