Weird photon behavior with Particle.function

I must be missing something but i’m not seeing it, when trying to post data to the api for a particle function i get the following message: {“ok”:false,“error”:“Timed out.”} not sure whats going on but i made sure the function name and anything calling it was less then the allowed number and when i make a similar call to a different device (sending different data but the url and method use to post is rougly the same where they both should be working

the code flashed on the photon is below (mind the chaos, its messy from trying different things to get this thing working):

    // This #include statement was automatically added by the Particle IDE.
    #include <neopixel.h>

    SYSTEM_MODE(AUTOMATIC);

    // IMPORTANT: Set pixel COUNT, PIN and TYPE
    #define PIXEL_PIN D2
    #define PIXEL_COUNT 144
    #define PIXEL_TYPE WS2812B

    Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

    bool lock = false;
    int red = 0;
    int grn = 0;
    int blu = 0;

    uint16_t heartRate = 433;//int heartRate = 833;
    int flashDuration = 50;

    void setup()
    {
      Particle.function("update", update);
      
      strip.setBrightness(15);
      strip.begin();
      strip.show(); // Initialize all pixels to 'off'
    }

    void loop() {
        
       if(lock == false){
            lock = true;
            //xLogoArray(500, true);
            //xLogoArray(500, false);
            updateLeds(heartRate, true);
            //Particle.publish("HeartRateLoop", heartRate);
            //Serial.print(heartRate);
            
            updateLeds(heartRate, false);
            lock = false;
        } 
        
        /*
        updateLeds(heartRate, true);
        updateLeds(heartRate, false); */
    }

    int update(String command) {
        //Particle.publish("HRComm", command);
        heartRate = command.toInt();
        //uint16_t hr = command.toInt();
        //heartRate = command;
        //Particle.publish("HeartRateComm", const char heartRate);
        return 1;
    }

    /*
    do 2d array with 0 being "color" and 1 being white. then when the array hits 0, apply color to that led, 
    when array hits 1, applay white.
    */

    uint8_t xLogo[16][16] = {  
     {0,0,0,0, 1,1,1,1, 1,1,1,1, 0,0,0,0 } ,   /*  initializers for row indexed by 0 */
     {0,0,0,1, 0,0,0,0, 0,0,0,0, 1,0,0,0 } ,   /*  initializers for row indexed by 1 */
     {0,0,0,1, 0,0,0,0, 0,0,0,0, 1,0,0,0 } ,   /*  initializers for row indexed by 2 */
     {0,0,1,0, 0,1,0,0, 0,0,1,0, 0,1,0,0 } ,   /*  initializers for row indexed by 3 */
     
     {0,0,1,0, 0,1,0,0, 0,0,1,0, 0,1,0,0 } ,   /*  initializers for row indexed by 4 */
     {0,1,0,0, 0,0,1,0, 0,1,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 5 */
     {0,1,0,0, 0,0,1,0, 0,1,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 6 */
     {1,0,0,0, 0,0,0,1, 1,0,0,0, 0,0,0,1 } ,   /*  initializers for row indexed by 7 */
     
     {1,0,0,0, 0,0,0,1, 1,0,0,0, 0,0,0,1 } ,   /*  initializers for row indexed by 8 */
     {0,1,0,0, 0,0,1,0, 0,1,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 9 */
     {0,1,0,0, 0,0,1,0, 0,1,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 10 */
     {0,0,1,0, 0,1,0,0, 0,0,1,0, 0,1,0,0 } ,   /*  initializers for row indexed by 11 */
     
     {0,0,1,0, 0,1,0,0, 0,0,1,0, 0,1,0,0 } ,   /*  initializers for row indexed by 12 */
     {0,0,0,1, 0,0,0,0, 0,0,0,0, 1,0,0,0 } ,   /*  initializers for row indexed by 13 */
     {0,0,0,1, 0,0,0,0, 0,0,0,0, 1,0,0,0 } ,   /*  initializers for row indexed by 14 */
     {0,0,0,0, 1,1,1,1, 1,1,1,1, 0,0,0,0 }    /*  initializers for row indexed by 15 */
    };

    uint8_t hLogo[16][16] = {  
     {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 0 */
     {0,0,0,0, 0,0,0,1, 0,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 1 */
     {0,0,0,0, 0,0,0,1, 0,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 2 */
     {0,0,0,0, 0,0,0,1, 0,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 3 */
     
     {0,0,0,0, 0,0,1,1, 1,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 4 */
     {0,0,0,0, 0,0,1,1, 1,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 5 */
     {0,0,0,0, 0,0,1,1, 1,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 6 */
     {0,0,0,0, 0,0,1,1, 1,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 7 */
     
     {0,0,0,0, 0,0,1,1, 1,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 8 */
     {0,0,0,0, 0,0,1,1, 1,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 9 */
     {0,1,0,0, 0,0,1,1, 1,0,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 10 */
     {0,0,1,1, 0,0,1,1, 1,0,0,0, 1,1,0,0 } ,   /*  initializers for row indexed by 11 */
     
     {0,0,1,1, 1,0,0,1, 0,0,1,1, 1,1,0,0 } ,   /*  initializers for row indexed by 12 */
     {0,0,0,1, 1,1,0,1, 0,0,1,1, 1,0,0,0 } ,   /*  initializers for row indexed by 13 */
     {0,0,0,1, 1,1,0,1, 0,1,1,0, 0,0,0,0 } ,   /*  initializers for row indexed by 14 */
     {0,0,0,0, 0,1,1,1, 1,1,0,0, 0,0,0,0 }    /*  initializers for row indexed by 15 */
    };

    void updateLeds(uint16_t heartBeat, bool backgroundOn)//, bool backgroundOn)
    {
        int k = 0;
        int beat = 300;
       
        for(int i = 0; i < 16; i++)
        {
            for(int j = 0; j < 16; j++)
            {
                //if(hLogo[i][j]==0)
                if(xLogo[i][j]==0)
                {
                    if (backgroundOn){
                        Serial.print("|");
                        Serial.print(heartBeat);
                        Serial.print("|");
                        if(heartBeat > 2000){// 2000 or 120bpm
                            strip.setPixelColor(k, strip.Color(255,0,0));//strip.setPixelColor(k, strip.Color(255,0,0));
                            beat = 250;
                        }else if(heartBeat >= 1999  && heartBeat >= 1701 ){ //110 bpm
                            strip.setPixelColor(k, strip.Color(255,128,0));//strip.setPixelColor(k, strip.Color(255,100,0));
                            beat = 275;
                        }else if(heartBeat <= 1700  && heartBeat >= 1501 ){ //100 bpm
                            strip.setPixelColor(k, strip.Color(255,255,0));//strip.setPixelColor(k, strip.Color(255,100,0));
                            beat = 275;
                        }else if(heartBeat <= 1500  && heartBeat >= 1334 ){ //90 bpm
                            strip.setPixelColor(k, strip.Color(128,255,0));//strip.setPixelColor(k, strip.Color(255,100,0));
                            beat = 350;
                        }else if(heartBeat <= 1333  && heartBeat >= 1167 ){ //80 bpm
                            strip.setPixelColor(k, strip.Color(0,255,0));//strip.setPixelColor(k, strip.Color(0,180,255));
                            beat = 425;
                        }else if(heartBeat <= 1166 && heartBeat >= 834 ){ //70 bpm
                            //strip.setPixelColor(k, strip.Color(0,90,127));//strip.setPixelColor(k, strip.Color(0,0,255));
                            strip.setPixelColor(k, strip.Color(0,0,255));
                            beat = 500;
                        } else if(heartBeat < 834){//50bpm
                            //strip.setPixelColor(k, strip.Color(77,24,127));//strip.setPixelColor(k, strip.Color(155,48,255));
                            strip.setPixelColor(k, strip.Color(127,0,255));
                            beat = 575;
                        } else
                        {
                        }
                        //strip.setPixelColor(k, strip.color(0,0,255));
                    }//set BgColor
                    else
                    {
                        strip.setPixelColor(k, strip.Color(0,0,0));
                    }
                }
                else{
                    //set white
                    strip.setPixelColor(k, strip.Color(255,255,255));
                }
                
                k++;
            }
            
        }
        
        strip.show();
        delay(beat);
    }



    uint8_t fLogo[16][16] = {  
     {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 0 */
     {0,0,0,0, 0,1,1,1, 1,1,1,0, 0,0,0,0 } ,   /*  initializers for row indexed by 1 */
     {0,0,0,0, 1,1,0,0, 0,0,1,1, 0,0,0,0 } ,   /*  initializers for row indexed by 2 */
     {0,0,0,1, 1,0,0,0, 0,0,0,1, 1,0,0,0 } ,   /*  initializers for row indexed by 3 */
     
     {0,0,1,1, 0,0,0,0, 0,0,0,0, 1,1,0,0 } ,   /*  initializers for row indexed by 4 */
     {0,1,1,0, 0,1,0,0, 0,0,1,0, 0,1,1,0 } ,   /*  initializers for row indexed by 5 */
     {0,1,0,0, 0,0,1,0, 0,1,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 6 */
     {0,1,0,0, 0,0,0,1, 1,0,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 7 */
     
     {0,1,0,0, 0,0,0,1, 1,0,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 8 */
     {0,1,0,0, 0,0,1,0, 0,1,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 9 */
     {0,1,1,0, 0,1,0,0, 0,0,1,0, 0,1,1,0 } ,   /*  initializers for row indexed by 10 */
     {0,0,1,1, 0,0,0,0, 0,0,0,0, 1,1,0,0 } ,   /*  initializers for row indexed by 11 */
     
     {0,0,0,1, 1,0,0,0, 0,0,0,1, 1,0,0,0 } ,   /*  initializers for row indexed by 12 */
     {0,0,0,0, 1,1,0,0, 0,0,1,1, 0,0,0,0 } ,   /*  initializers for row indexed by 13 */
     {0,0,0,0, 0,1,1,1, 1,1,1,0, 0,0,0,0 } ,   /*  initializers for row indexed by 14 */
     {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }    /*  initializers for row indexed by 15 */
    };

    uint8_t cLogo[16][16] = {  
     {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 } ,   /*  initializers for row indexed by 0 */
     {0,0,0,0, 0,1,1,1, 1,1,1,0, 0,0,0,0 } ,   /*  initializers for row indexed by 1 */
     {0,0,0,0, 1,1,0,0, 0,0,1,1, 0,0,0,0 } ,   /*  initializers for row indexed by 2 */
     {0,0,0,1, 1,0,0,0, 0,0,0,1, 1,0,0,0 } ,   /*  initializers for row indexed by 3 */
     
     {0,0,1,1, 0,0,0,0, 0,0,0,0, 1,1,0,0 } ,   /*  initializers for row indexed by 4 */
     {0,1,1,0, 0,1,0,0, 0,0,1,0, 0,1,1,0 } ,   /*  initializers for row indexed by 5 */
     {0,1,0,0, 0,0,1,0, 0,1,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 6 */
     {0,1,0,0, 0,0,0,1, 1,0,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 7 */
     
     {0,1,0,0, 0,0,0,1, 1,0,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 8 */
     {0,1,0,0, 0,0,1,0, 0,1,0,0, 0,0,1,0 } ,   /*  initializers for row indexed by 9 */
     {0,1,1,0, 0,1,0,0, 0,0,1,0, 0,1,1,0 } ,   /*  initializers for row indexed by 10 */
     {0,0,1,1, 0,0,0,0, 0,0,0,0, 1,1,0,0 } ,   /*  initializers for row indexed by 11 */
     
     {0,0,0,1, 1,0,0,0, 0,0,0,1, 1,0,0,0 } ,   /*  initializers for row indexed by 12 */
     {0,0,0,0, 1,1,0,0, 0,0,1,1, 0,0,0,0 } ,   /*  initializers for row indexed by 13 */
     {0,0,0,0, 0,1,1,1, 1,1,1,0, 0,0,0,0 } ,   /*  initializers for row indexed by 14 */
     {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }    /*  initializers for row indexed by 15 */
    };

the code i am using to post is in c# but is below:

    string accessToken = "----redacted---";
                string deviceId = "1c0038000447343138333038";
                string particleFunc = "update";
                string DEVICE_URI_ENDPOINT = "https://api.particle.io/v1/devices/"; //"https://api.spark.io/v1/devices/";

                //var requestContent = new FormUrlEncodedContent(new[]
                //{
                //    new KeyValuePair<string, string>("access_token", accessToken),
                //    new KeyValuePair<string, string>("args", heartRate.ToString() )
                //});
                var requestContent = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("arg", heartRate.ToString()) });
                System.Diagnostics.Debug.WriteLine(heartRate);
                try
                {

                    using (var client = new HttpClient())
                    {
                        var response = await client.PostAsync(
                            DEVICE_URI_ENDPOINT + deviceId + "/" + particleFunc + "?access_token=" + accessToken,
                            requestContent);
                        //var response = await client.PostAsync(
                        //    DEVICE_URI_ENDPOINT + deviceId + "/" + particleFunc,
                        //    requestContent);
                        var responseText = await response.Content.ReadAsStringAsync();
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                }

Other things to note:
when going to https://api.particle.io/v1/devices/1c0038000447343138333038/?access_token={mytokenhere} in a browser i get this:

{"id":"1c0038000447343138333038","name":"Starlight","last_app":null,"last_ip_address":"65.29.131.42","last_heard":"2018-04-05T23:31:18.866Z","product_id":6,"connected":false,"platform_id":6,"cellular":false,"notes":null,"status":"normal","serial_number":"PKIT-150611-7ADB-0","current_build_target":"0.7.0","system_firmware_version":"0.7.0","default_build_target":"0.7.0","variables":null,"functions":null,"cc3000_patch_version":"wl0: Nov  7 2014 16:03:45 version 5.90.230.12 FWID 01-93c9c012"}

thats weird, it says its not “connected” but clearly is and is pulsing cyan… also id like to point out that this is happening still when I switch devices…

any thoughts on whats going on and why it wont accept this command when testing the similar calls on other devices works but only THIS call causes the timeout

For the POST request the access_token should also be passed in the request content as outlined in the docs for Particle.function()

You could also use the Particle API JS

@ScruffR I tried that, but it returns the same timeout as above, also if that is the case then why is it only timing out not returning a proper 400 error?

code is updated to:

    var requestContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("access_token", accessToken),
                    new KeyValuePair<string, string>("args", heartRate.ToString() )
                });
    try
                {

                    using (var client = new HttpClient())
                    {
                        //var response = await client.PostAsync(
                        //    DEVICE_URI_ENDPOINT + deviceId + "/" + particleFunc + "?access_token=" + accessToken,
                        //    requestContent);
                        var response = await client.PostAsync(
                            DEVICE_URI_ENDPOINT + deviceId + "/" + particleFunc,
                            requestContent);
                        var responseText = await response.Content.ReadAsStringAsync();
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                }

still getting the timeout error.

the code that i send to another device that does work from the same network and wifi access point is:

    string partilceFunc = "ledcolor";

                HttpClient client = new HttpClient {BaseAddress = 
                    new Uri("https://api.particle.io/")};

                var content = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("access_token", accessToken),
                    new KeyValuePair<string, string>("args", changeValue )
                });

                var result = client.PostAsync("v1/devices/" + deviceId + "/" + partilceFunc, content).Result;

Does the function call work with console.particle.io/devices ?

yes, when i use that feature it does work. the code i have for the other app is both being called from the same phone as well.

I did however find a math bug that would set the wrong value for HR due to a rounding issue, but that didn’t solve the problem

@ScruffR,

Thinking a bit here, would where i am doing the logic with the returned value cause an issue (see difference below).

The command code from the “issue” photon:

/* ======================= sets up function phone app calls ================================= */
int update(String command) {
    heartRate = command.toInt();
    return 1;
}

the working command code logic on the photon:

int ledColor(String command)
{
    
     //switch(command){
        //case "off":
            
        //case "eeryforest":
            
        //case "white":
          
    
    if(command == "white")
    {
        whiteStrip(20);
        return 1;
    }
    else if(command == "pink")
    {
        pinkStrip(20);
        return 1;
    }
    else if(command == "red")
    {
        redStrip(20);
        return 1;
    }
    else if(command == "orange")
    {
        orangeStrip(20);
        return 1;
    }
    else if(command == "yellow")
    {
        yellowStrip(20);
        return 1;
    }
    else if(command == "green")
    {
        greenStrip(20);
        return 1;
    }
    else if(command == "cyan")
    {
        cyanStrip(20);
        return 1;
    }
    else if(command == "blue")
    {
        blueStrip(20);
        return 1;
    }
    else if(command == "Blue")
    {
        blueStrip(20);
        return 1;
    }
    else if(command == "purple")
    {
        purpleStrip(20);
        return 1;
    }
    else if(command == "magenta")
    {
        magentaStrip(20);
        return 1;
    }
    else if(command == "off")
    {
        off(20);
        return 1;
    }
    else if (command == "eeryforest"){
        eeryForest(20);
        return 1;
    }
    else if (command == "alter"){
        floatlight(20);
        return 1;
    }
    
    else return -1; 
}

I didn’t think so but if this is, i am stuck with trying to rework this as i need the loop to make this code work and not sure how to rework this so the timing is correct otherwise…

I don’t see an issue either, but I usually try to propose to use the return value in a more creative manner than just returning a “non-descript” flag - after all there are 2^32 possible values to return, why only ever return such a limited subset of the actual value range?

e.g. rather do

int update(String command) {
    heartRate = command.toInt();
    return heartRate;
}

this actually carries real information not just a unimaginative 1.

Or your other function, I’d rewrite like that

const char colors[][12] = 
{ "off"
, "white"
, "pink"
, "red"
, "orange"
, "yellow"
, "green"
, "cyan"
, "blue"
, "purple"
, "magenta"
, "eeryforest"
, "alter"
};
const int colorCount = sizeof(colors) / sizeof(colors[0]);

int ledColor(String command)
{
  for (int i = 0; i < colorCount; i++) {
    if (command.equalsIgnoreCase(colors[i]) {
      setStrip(i, 20);
      return i;      
    }
  }
  return -1;
}

That way you can also add as many colors you like without need for any change in the actual function logic.

Also since you can successfully call the function via console.particle.io, it’s obviously not a problem with the function but with the way how it’s called.

One shot into the blue might also be to arbitrary change the function name or just swap the calls - i.e. just make the working call calling the “not working” function and vice versa.

@ScruffR I will try this… to be fair the code i started with was working from a project i did back in 2016, so something on particles end changed since then to make the code i had no longer work. (see attacked image to the post)

I also was using https://api.spark.io/v1/devices api before instead of https://api.particle.io which now refuses to work at all (i’m guessing deprecated) as i get an authentication error…

I will take a look at the rework suggestions for the other project and update them in this project: https://www.hackster.io/MobileRez/colorful-home-lighting-control-with-xamarin-particle-photon-65323a,

However this is the entire code I need to rework…

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

/* ======================= includes ================================= */

SYSTEM_MODE(AUTOMATIC);


// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
//#define PIXEL_COUNT 255 
#define PIXEL_COUNT 144
#define PIXEL_TYPE WS2812B

//Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int ledState = 0;
uint8_t bLevel = 15;
bool lock = false;
int red = 0;
int grn = 0;
int blu = 0;

uint16_t heartRate = 433;//int heartRate = 833;
int flashDuration = 50;

/* ======================= arduino/phonton core code ================================= */

void setup() {
    strip.begin();
    strip.setBrightness(bLevel);
    strip.show(); // Initialize all pixels to 'off'
    Particle.function("update", update);
}

void loop() {
if(lock == false){
        lock = true;
        updateLeds(heartRate, true);
        
        updateLeds(heartRate, false);
        lock = false;
    } 
}


/* ======================= sets up function phone app calls ================================= */
//int update(String command) {
//    heartRate = command.toInt();
//    return 1;
//}

int update(String command) {
    heartRate = command.toInt();
    return heartRate;
}

/* ======================= sets led color based on heartrate ================================= */
void updateLeds(uint16_t heartBeat, bool backgroundOn)//, bool backgroundOn)
{
    int k = 0;
    int beat = 300;
   
    for(int i = 0; i < 16; i++)
    {
        for(int j = 0; j < 16; j++)
        {
            //if(hLogo[i][j]==0)
            //if(xLogo[i][j]==0)
            //{
                if (backgroundOn){
                    Serial.print("|");
                    Serial.print(heartBeat);
                    Serial.print("|");
                    if(heartBeat > 2000){// 2000 or 120bpm
                        strip.setPixelColor(k, strip.Color(255,0,0));//strip.setPixelColor(k, strip.Color(255,0,0));
                        beat = 250;
                    }else if(heartBeat >= 1999  && heartBeat >= 1701 ){ //110 bpm
                        strip.setPixelColor(k, strip.Color(255,128,0));//strip.setPixelColor(k, strip.Color(255,100,0));
                        beat = 275;
                    }else if(heartBeat <= 1700  && heartBeat >= 1501 ){ //100 bpm
                        strip.setPixelColor(k, strip.Color(255,255,0));//strip.setPixelColor(k, strip.Color(255,100,0));
                        beat = 275;
                    }else if(heartBeat <= 1500  && heartBeat >= 1334 ){ //90 bpm
                        strip.setPixelColor(k, strip.Color(128,255,0));//strip.setPixelColor(k, strip.Color(255,100,0));
                        beat = 350;
                    }else if(heartBeat <= 1333  && heartBeat >= 1167 ){ //80 bpm
                        strip.setPixelColor(k, strip.Color(0,255,0));//strip.setPixelColor(k, strip.Color(0,180,255));
                        beat = 425;
                    }else if(heartBeat <= 1166 && heartBeat >= 834 ){ //70 bpm
                        //strip.setPixelColor(k, strip.Color(0,90,127));//strip.setPixelColor(k, strip.Color(0,0,255));
                        strip.setPixelColor(k, strip.Color(0,0,255));
                        beat = 500;
                    } else if(heartBeat < 834){//50bpm
                        //strip.setPixelColor(k, strip.Color(77,24,127));//strip.setPixelColor(k, strip.Color(155,48,255));
                        strip.setPixelColor(k, strip.Color(127,0,255));
                        beat = 575;
                    } else
                    {
                    }
                    //strip.setPixelColor(k, strip.color(0,0,255));
                }//set BgColor
                else
                {
                    strip.setPixelColor(k, strip.Color(0,0,0));
                }
            //}
            //else{
                //set white
            //    strip.setPixelColor(k, strip.Color(255,255,255));
            //}
            
            k++;
        }
        
    }
    
    strip.show();
    delay(beat);
}

its a little trickier as the particle’s C++ syntax seems slightly different to others

1 Like

Hmm, can you elaborate in what way or provide an example?

Mostly I think its because i have been living in the higher coding world of C# but when looking at https://docs.particle.io/reference/firmware/photon/#particle-publish- trying to debug the code, the examples from the api…

Particle.publish(String eventName, String data); 
Particle.publish(const char *eventName, const char *data);

returns the error:

fbhrbiofeed.ino:41:33: expected primary-expression before 'eventName'
error
fbhrbiofeed.ino:41:51: expected primary-expression before 'data'

when building the code and those variables are defined and typed beforehand. It also seems finicky when trying to convert variables which is causing me to have to implicitly type things and if i cant, find a different way to approach it sometimes leading to some rather horrid code…

example: in the code above the variable heartRate is an int. however when using the publish, it wont accept ints, theirfor i get the error:

fbhrbiofeed.ino:41:43: invalid conversion from 'uint16_t {aka short unsigned int}' to 'const char*' [-fpermissive]

and all attempts to convert it to a string, don’t work too well

These are the function signatures, not direct examples. You can give publish a String and a String or you can give it a char array and a char array.

1 Like

All you stated there is nothing specific to a “Particle version” of C++ but it’s standard C++.
Which is not surprising since the compiler used by Particle is a vanilla gcc for STM32.

If you come from a C# background, then that is actually further away from C++ than what’s used on Particle devices.

@bko oh i see, the only complete example is

// EXAMPLE USAGE
bool success;
success = Particle.publish("motion-detected");
if (!success) {
  // get here if event publish did not work
} 

yay learning! I assumed the rest was also valid because of the first example but the docs are a bit confusing since the way its formatted starts with an example and then continues with more code and not the possible variations of the way you can work with Particle.publish. perhaps there is a way to remove this ambiguity?

Still trying to figure out this initial issue…

@ScruffR @bko
ah i see i have to define the format...

so instead i should use...

sprintf(publishString, "%d", heartRate);
Particle.publish("HRLoop", publishString);

these little nuisances are going to catch me up i think...

update: IT WAS THE STUPID DEVICE ID!!!

UGH… i had 1c0038000447343138333038 when i really needed 310034000847343337373738

I hope the mesh devices end in different numbers…

1 Like

What do you mean by that?
The device IDs are semi-random 24-hex-digit numbers, so anything is possible.
Purely statistically seen, one out of 256 devices will end up in exactly these same two end-digits.

How would the choice for future device IDs save anybody from failing to correctly copy/pasting them?
I wouldn't blame it on the device ID - apart from it being inanimate and hence incapable of wrong-doing, it'd be hardly its fault.

1 Like

@ScruffR and i didn’t chose to be dyslexic… and since your site does not use a dyslexic friendly font, i figured it might be easier to change that then the entire site.

that said, i probably switched devices and forgot about it. still a timeout error doesn’t really give a good indication that the device if offline or invalid it would lead a person to think that the device id would not be the problem because it didn’t error out as you would expect, but time out (communication/network like issue)

so yes, its not the devices fault as the last post seemed to imply, but the API / current system is not perfect either.