Struggling to figure out an error

I’m very new at this and trying to build a function on a particle photon. I can’t seem to figure out how to resolve this error. Research has me thinking that it has to do with needing to pass a string to the function, but even when I add a string the “signal” variable still throws the error.

These are the errors:

../wiring/inc/spark_wiring_cloud.h:193:39: invalid conversion from 'int (*)(signal*)' to 'int (*)(String)' [-fpermissive] ../wiring/inc/spark_wiring_cloud.h:196:17: initializing argument 2 of 'static bool CloudClass::_function(const char*, int (*)(String))' [-fpermissive]

This is the code:



const int TX_PIN = 3;   // Particle photon pin 3

typedef struct  {
    boolean power;
    int duration;   // micro seconds
} signal;

const signal SHORT_ON { true, 400 };
const signal SHORT_OFF { false, 500 };
const signal LONG_ON { true, 850 };
const signal LONG_OFF { false, 950 };
const int REST = 10000;

const char* host = "fancontrol";


signal sig_preamble [] {   // 50 items total
    SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF,
    SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF,
    SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF,
    SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF, SHORT_ON, LONG_OFF
};

signal sig_power [] {
    SHORT_ON, SHORT_OFF,
    LONG_ON, SHORT_OFF,
    LONG_ON, SHORT_OFF,
    LONG_ON, SHORT_OFF,
    LONG_ON, LONG_OFF,
    SHORT_ON, LONG_OFF,
    SHORT_ON, SHORT_OFF,
    LONG_ON, LONG_OFF
};

signal sig_1 [] {
    SHORT_ON, LONG_OFF,
    SHORT_ON, SHORT_OFF,
    LONG_ON, SHORT_OFF,
    LONG_ON, SHORT_OFF,
    LONG_ON, LONG_OFF,
    SHORT_ON, LONG_OFF,
    SHORT_ON, SHORT_OFF,
    LONG_ON, LONG_OFF
};

signal sig_2 [] {
    SHORT_ON, SHORT_OFF,
    LONG_ON, LONG_OFF,
    SHORT_ON, SHORT_OFF,
    LONG_ON, SHORT_OFF,
    LONG_ON, LONG_OFF,
    SHORT_ON, LONG_OFF,
    SHORT_ON, SHORT_OFF,
    LONG_ON, LONG_OFF
};

signal sig_3 [] {
    SHORT_ON, LONG_OFF,
    SHORT_ON, LONG_OFF,
    SHORT_ON, SHORT_OFF,
    LONG_ON, SHORT_OFF,
    LONG_ON, LONG_OFF,
    SHORT_ON, LONG_OFF,
    SHORT_ON, SHORT_OFF,
    LONG_ON, LONG_OFF
};


int doIT(signal array[16]) {
    Serial.println("Doing transmission...");
    for (int burst = 1; burst <= 6; burst++) {
        for (int pre = 0; pre < 32; ++pre) {    // Preamble
            digitalWrite(TX_PIN, sig_preamble[pre].power);
            delayMicroseconds (sig_preamble[pre].duration);
        }
        for (int idx = 0; idx < 16; ++idx ) {   // payload
            digitalWrite(TX_PIN, array[idx].power);
            delayMicroseconds( array[idx].duration );
        }
        digitalWrite(TX_PIN, SHORT_ON.power);   // postamble - is that a word?
        delayMicroseconds(SHORT_ON.duration);
        digitalWrite(TX_PIN, SHORT_OFF.power);
        delayMicroseconds(REST);                // rest between bursts
     return 1;
    }
}


void loop() {

}



void setup() {
    Particle.function("doTrans", doIT);
}

here in the docs...

// SYNTAX
bool success = Particle.function("funcKey", funcName);

// Cloud functions must return int and take one String <<<<<<<<<<<<<<<<<<<
int funcName(String extra) {
return 0;
}

your function expects something else....

int doIT(signal array[16]) {...

...
Particle.function("doTrans", doIT);
2 Likes

Thanks for that. I got it working by creating a new function with only the one string input and then using if statements to call the other routine. So I’m all ready to go, but now I can’t call it, lol.

I’m on windows and don’t know the best way to send commands. I can see the particle from a command prompt and it sees my function when i type particle call, but when i try and run the function using:

particle call (device id) doTrans(3)

I get an error “function call failed permission denied”. I also tried the curl string, but it doesn’t even recognize “curl”.

Is the command prompt the best way to send commands for testing? How do I use the curl command?

I seen on a youtube video someone was able to open a terminal from the web interface, but I can’t tell what hot key he pressed to type “terminal” before it launched.

finally got it working using this string from cmd prompt

particle call device_id doTrans 3

You can also use the device's name instead of the id, which is a lot shorter :wink:

1 Like

The Particle console has a nice UI for that, and so do the mobile apps :slight_smile:

How do I launch it from a windows laptop, lol. Did end up getting it to work from the command line. Thanks all for the help!

top of this post… hot link to CONSOLE

2 Likes

In case that doesn’t work…

Thanks for pointing me back. I’d been on that terminal 20 times before and couldn’t do anything from it. Just now found that there is a “device” section that let me run the curl function from.