When I send my imp to deep sleep using “deepsleepfor()” command, after wakingup the scan events comes as “LOG: event unknown (unhandled)” instead of “LOG: event gap_scan_response”
Hi hugo,
I found a solution.
imp.wakeup(10, function() {
imp.deepsleepfor(60);
});
Instead of calling imp.deepsleepfor(60); in onidle() I am calling it in imp.wakeup()
It worked fine, in this also if I make time 10->0.0 again same problem starts. and for other values less than 10 it some times recognises the event some times it dont. also I dry run the code I found the uart.read() is not reading correct headers (I think).
Did this gave you any clue what might be the possible problem?
“reinitializing the BLE after waking” I did not get, It will be always reinitialized after waking from deep sleep as code execution starts from the begining again, am I correct so I suppose waking from deepsleep is equivalent to fresh starting the imp?
I think there are many callbacks in the queue so befor all the call Backs fire imp again goes to deep sleep.(am I correct?)
10 secs is also not reliable it sometimes don’t work, again when the device is restarted it works.
The data I need is in the read buffer data but is preceded with other data also, I think the buffer is getting full and after reading the buffer parser is not able to parse it properly.
These informations may help to give some clue what might be the problem.
Leaving time before sleeping will not affect how the imp behaves on the next powerup. When the imp wakes, it is essentially a fresh boot of squirrel - all RAM contents have been lost, so there is no context at all.
My guess is that the BLE chip is not being powered down when the imp sleeps, and so has been continuing to send scan results to the imp. When the imp wakes and configures its UART, there are random bytes from the middle of packets being received which is confusing the code.
Hence you need to ensure the BLE chip is reinitialized, buffers emptied, etc before trying to start fresh.
I’m afraid debugging this code is not something we can help you with. If you were using the built-in BLE of imp004m then we could help you.
I am flushing the buffer and disabling The UART also and then lowering the waKeup pin of BLE again I check it for its state then call imp.deepsleepfor(20); The BLE is reinitialized at the begining of the code. Where am I doing wrong? i am not getting
As I said, I can’t help debug an application whose problem is with another device that we don’t have and don’t support…
Flushing a UART before sleeping is pointless; sleeping, as noted, loses all ram content (and IO configuration). You need to ensure you’re in sync with the BLE chip when you wake up. ie, stop changing how you go to sleep, and start looking at how to get back in sync when you start up.
Note also that ALL GPIOs are tristated when the imp is in sleep. Seems like there should be a pull-down resistor on your wakeupPin to ensure it stays low when the imp is sleeping, otherwise the BLE chip may wake the second the imp sleeps.