Argon Particle.function failed to call

Hi Everyone,

I am trying to call particle function in my argon device but it always says failed to call the function. Can anyone tell me what I am doing wrong in my code?

char devName[32] = "W0001"; /**<Declaring the Device ID */
char jsonData[256]; /**< Variable declared to hold the JSON formatted data */
bool cloudSuccess; /**< Variable declared for checking cloud upload*/
char recData[30]; /**< Varibale to hold UART data*/

int count = 0;
int t=30 ;
float vfr= 0;  
int timeInteraval(String seconds);

// setup() runs once, when the device is first turned on.
void setup() {

  // Put initialization like pinMode and begin functions here.
    Serial1.begin(115200); /**< UART Initialized*/
    //Registering the function
    Particle.function("time", timeInteraval);
// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.
   /* Checks whether particle is connected to cloud*/
        /* Checks whether UART data is available*/
            tone(D3, 20, 50); /**< LED Signal*/
            /* Reading the serail data*/
            String s = Serial1.readStringUntil('\n');
            s.toCharArray(recData, 30);
            /* Stripping the string using delimit*/
            char * dlimiter = strtok(recData,",");
            char * dData = strtok(NULL,",");
            int d = atoi(dlimiter);
                /*Converting hex to float*/
                std::string s = dData;
                unsigned int x = std::stoul(s, nullptr, 16);
                static_assert(sizeof(float) == sizeof x, "`float` has a weird size.");
                float ret;
                std::memcpy(&ret, &x, sizeof(float));             
               vfr = vfr + ret;
                count= count+1;
                if (count==t)
                        /* Saving the Local Time in UNIX time format*/
                    int uf_time = Time.local();
                    /* Writing the data into JSON format */
                    JSONBufferWriter writer(jsonData, sizeof(jsonData));
                    writer.buffer()[std::min(writer.bufferSize(),writer.dataSize())] = 0;
                    if(dData!= 0)
                        /* Publishing data to particle cloud */
                        cloudSuccess = Particle.publish("RTR_FlowMeter_data", jsonData);
// This function is called when the Particle.function is called
int timeInteraval(String seconds)
        return 1;

Thanks in Advance

You have an virtual infinite while(Particle.connected()) but Particle.function() request would be services between iterations of loop().

You could use SYSTEM_THREAD(ENABLED), but the better approach would be to not keep your code flow trapped in any loop for a prolonged period of time.

1 Like

Thanks a million for your quick response.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.