spark-sdk-ios icon indicating copy to clipboard operation
spark-sdk-ios copied to clipboard

Calling function while subscribed to events results in timeout

Open JSchaenzle opened this issue 9 years ago • 5 comments

I am using the latest release of the SDK, Version 0.3.4. For some reason, if my app subscribes to an event, I cannot seem to call functions (using callFunction)on my device. If I do not subscribe to the event, the function calls work perfectly and the completion block is called quickly as expected. When I subscribe to an event, the subscription works fine and my app receives events published from my device, however when I call a function, the call times out after about 20 seconds. The error info is below.

Has anyone experienced this? I haven't ruled out that it's something that I am doing wrong but I've been wrestling with this for a while and not making any progress. Are there any requirements about what thread you call callFunction from or subscribeToEventsWithPrefix()?

"Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSUnderlyingError=0x7f9b6420e930 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=https://api.particle.io/v1/devices/40002b000447343233323032/set-tc-temp, NSErrorFailingURLKey=https://api.particle.io/v1/devices/40002b000447343233323032/set-tc-temp, _kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4, NSLocalizedDescription=The request timed out.}}, NSErrorFailingURLStringKey=https://api.particle.io/v1/devices/40002b000447343233323032/set-tc-temp, NSErrorFailingURLKey=https://api.particle.io/v1/devices/40002b000447343233323032/set-tc-temp, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}">

From my Podfile.lock:

  • Spark-SDK (0.3.4):
    • Spark-SDK/Helpers (= 0.3.4)
    • Spark-SDK/SDK (= 0.3.4)
  • Spark-SDK/Helpers (0.3.4)
  • Spark-SDK/SDK (0.3.4):
    • AFNetworking (< 3.0.0)
    • Spark-SDK/Helpers

JSchaenzle avatar Feb 21 '16 02:02 JSchaenzle

I will check it, thanks for reporting

idokleinman avatar Feb 21 '16 07:02 idokleinman

@JSchaenzle I tried reproducing this and could not - I was able to call a function on the photon device after being subscribed to an event stream without any issue. I assume you are doing something wrong. If you want me I will post the full iOS Swift code + photon firmware C code I created while trying to repro this issue, so you can maybe compare against and see if you did something wrong.

idokleinman avatar Feb 25 '16 04:02 idokleinman

@idokleinman Thanks for checking. I don't think it's necessary for you to post your code right now. I'll keep digging into it on my side. If I can find a simple process to reproduce the issue I'll let you know.

JSchaenzle avatar Feb 25 '16 14:02 JSchaenzle

For reference / other users, posting the C photon firmware code I used to test this issue:

int LED = D7;
int testVariable=64;

int testFunction(String command) {
    for (int i=0;i<5;i++) {
        digitalWrite(D7, HIGH);
        delay(100);
        digitalWrite(D7, LOW);
        delay(100);
    }
    Particle.publish("test-func-called");   
}

void setup() {
    pinMode(D7, OUTPUT);
    Particle.function("testFunc",testFunction);
    Particle.variable("testVar", &testVariable, INT);

}

void loop() {
    digitalWrite(D7, HIGH);
    delay(1000);
    digitalWrite(D7, LOW);
    delay(1000);
    Particle.publish("test-event");
}

idokleinman avatar Feb 26 '16 19:02 idokleinman

and the test code on iOS-land is here: https://github.com/spark/spark-setup-ios-example/blob/master/SparkSetupExample-Swift/ViewController.swift#L93-L242

no issues encountered. Update me if you find anything, otherwise I'm closing this issue.

idokleinman avatar Feb 26 '16 19:02 idokleinman