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