Custom iOS app using the SDK doesn't interact with device

I’m following the tutorial and reference guide to be able to create my own iOS app for the Particle Photon, however I’m facing a small issue.

@IBAction func login(sender: Any) {
        SparkCloud.sharedInstance().login(withUser: email, password: password) { (error:Error?) -> Void in
            if let _ = error {
                print("Wrong credentials or no internet connectivity, please try again")
            }
            else {
                print("Logged in")
                var myPhoton : SparkDevice?
                SparkCloud.sharedInstance().getDevices { (devices:[SparkDevice]?, error:Error?) -> Void in
                    if let _ = error {
                        print("Check your internet connectivity")
                    }
                    else {
                        if let d = devices {
                            for device in d {
                                myPhoton = device
                                print(myPhoton!)
                                let funcArgs = ["D7",1] as [Any]
                                _ = myPhoton?.callFunction("digitalWrite", withArguments: funcArgs) { (resultCode : NSNumber?, error : Error?) -> Void in
                                    if (error == nil) {
                                        print("LED on D7 successfully turned on")
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

Everything works and I manage to connect to my Particle Photon, however the LED on my Particle Photon doesn’t actually light up. I’m still new to this. Can anyone help me please? Thanks.

If Tinker is running on the device, you’ll need to have the argument be “D7,HIGH”.

2 Likes

Wow thank you very much! It started working! Can you please explain a little for me on what was the difference? Thanks.

If you look at the code, that’s what it expects:
https://docs.particle.io/guide/getting-started/examples/photon/#tinker

/*******************************************************************************
 * Function Name  : tinkerDigitalWrite
 * Description    : Sets the specified pin HIGH or LOW
 * Input          : Pin and value
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 *******************************************************************************/
int tinkerDigitalWrite(String command)
{
    bool value = 0;
    //convert ASCII to integer
    int pinNumber = command.charAt(1) - '0';
    //Sanity check to see if the pin numbers are within limits
    if (pinNumber < 0 || pinNumber > 7) return -1;

    if(command.substring(3,7) == "HIGH") value = 1;       // <------- over here.
    else if(command.substring(3,6) == "LOW") value = 0;      // <------- over here.
    else return -2;

    if(command.startsWith("D"))
    {
        pinMode(pinNumber, OUTPUT);
        digitalWrite(pinNumber, value);
        return 1;
    }
    else if(command.startsWith("A"))
    {
        pinMode(pinNumber+10, OUTPUT);
        digitalWrite(pinNumber+10, value);
        return 1;
    }
#if Wiring_Cellular
    else if(command.startsWith("B"))
    {
        if (pinNumber > 5) return -4;
        pinMode(pinNumber+24, OUTPUT);
        digitalWrite(pinNumber+24, value);
        return 1;
    }
    else if(command.startsWith("C"))
    {
        if (pinNumber > 5) return -5;
        pinMode(pinNumber+30, OUTPUT);
        digitalWrite(pinNumber+30, value);
        return 1;
    }
#endif
    else return -3;
}
2 Likes