i have an iOS app and i want to use https://docs.particle.io/reference/firmware/photon/#wifi
in the native code. Is there any way to make the particle photon in listen mode without pressing the listening mode button the the device from the app?
There are at least two other ways to force listening mode (blinking blue), which enables the SoftAP.
If you never configure Wi-Fi credentials on the device, it will boot into listening mode. You can clear them by holding down SETUP until the status LED blinks blue, then continue to hold down SETUP until it blinks blue rapidly (about 10 seconds longer).
If you call WiFi.listen() from your code, you will go into listening mode as well.
You can’t just do it from a mobile app unless you have some other channel to invoke it, for example if both the device and phone are online you could trigger listening mode with a Particle.function.
I am connected to photon i have all the details of the device now i want to make the device go into listening mode i tried from the SDK of Particle but i wasnt able to find the listening function. How do i call the listen function.
Note: I am connected to the device. I just want to make it go into listen mode so that i can change its wifi.
How about this
https://docs.particle.io/reference/firmware/photon/#listen-
This is how it runs in iOS objective C. I cannot directly use https://docs.particle.io/reference/firmware/photon/#listen-
This does not work. it gives me 404 error
Now how to use this in iOS? Because there is no library where there is WiFi function declared
WiFi.listen();
You need to expose a Particle.function()
which in turn calls WiFi.listen()
or rather sets a flag which is checked in loop()
to engage Listening Mode.
This is what @rickkas7 meant when he said
There is no Particle
. Hence i cannot call Particle.function()
This is the iOS SDK
There are 2 parts to what you’re doing… (1) the Photon firmware and (2) the iOS app. Particle.function() exists in the device firmware (NOT the iOS SDK). You call Particle.function() in the firmware to expose a function. In Objective C, you use this example to call that function that you created in the firmware.
NSURLSessionDataTask *task = [myPhoton callFunction:@"digitalWrite" withArguments:@[@"D7",@1] completion:^(NSNumber *resultCode, NSError *error) {
if (!error)
{
NSLog(@"LED on D7 successfully turned on");
}
}];
int64_t bytesToReceive = task.countOfBytesExpectedToReceive;
// ..do something with bytesToReceive
Here is a link to the Particle.function() in the firmware reference: Particle.function()
What do i need to import in order to call WiFi.listen()
because it is giving me error
no matching function for call to 'CloudClass::_function(void (&)())'
i have already imported
#include "Particle.h"
#include "softap_http.h"
You need to show the code line that causes the error.
This error message does not indicate the function wasn’t found (imported) but that you have been using it wrong.
By looking at the error message alone I’d deduce that you wrote something like this
Particle.function(WiFi.listen());
Right?
Consequently (and by the over-all history of this thread) I guess you haven’t had a close look at the docs @ninjatill linked above in regards of how to use Particle.function()
or to develop the firmware for Particle devices in general.
#include "Particle.h"
#include "softap_http.h"
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);
void setup() {
WiFi.on();
WiFi.clearCredentials();
Particle.function("asdad",tryingToConnectToWifi);
}
void tryingToConnectToWifi(String FCommands)
{
WiFi.listen();
}
void loop() {
}
How about this (from the docs sampel)
bool success = Particle.function("funcKey", funcName);
// Cloud functions must return int and take one String
int funcName(String extra) {
return 0;
}
Your function is a void fn(String)
but Particle.function()
expects an int fn(String)
and this function has to feature a return someInt;
line.
That's what the error message complains about
no matching function for call to 'CloudClass::_function(
void
(&)())'
However, after a WiFi.clearCredentials()
and without Particle.connect()
in SYSTEM_MODE(MANUAL)
your device will never connect to the cloud to actually make it available for a remote caller, so the over-all logic of this project is somewhat obscure.
This is also what @rickkas7 meant when he said
Also the two options (clearing credentials or Particle.function()
) were meant as alternative ways to achieve the same thing (depending on need), not both unconditionally.
To cut things short I'd rather go with someting like this
#include "Particle.h"
#include "softap_http.h"
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
bool enterLM = false;
void setup() {
Particle.function("startListen", enterListeningMode);
Particle.connect();
}
void loop() {
if (enterLM) {
enterLM = false;
WiFi.listen();
}
}
int enterListeningMode(String dummy)
{
enterLM = true;
return 1;
}
Then you can engage LM with this
NSURLSessionDataTask *task = [myPhoton callFunction:@"startListen" withArguments:@[@"",@1] completion:^(NSNumber *resultCode, NSError *error) {
if (!error)
{
NSLog(@"device should be in Listening Mode now");
}
}];
Thank you guys a lot. @ninjatill @rickkas7 @ScruffR all you guys thank you for being so supportive and patient. It worked.