spark-sdk-ios
spark-sdk-ios copied to clipboard
Calling function while subscribed to events results in timeout
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
I will check it, thanks for reporting
@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 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.
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");
}
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.