After few days of work I can no longer connect to my puck #3851
Replies: 1 comment
-
Posted at 2021-08-16 by @gfwilliams Have you tried connecting from a different computer, or just restarting your computer? Sometimes the browser/bluetooth stack on the PC can get confused and will refuse to connect - it might not be the Puck at all Posted at 2021-08-17 by user130485 Tried various things - none help. Only hard reset is working. PS: OK, worked out the part where I cannot connect to it. It must have done a reboot or whatever, which has caused this to kick in: NRF.setSecurity({display : 1, mitm : 1, bond : 1, passkey : '123456'}); Posted at 2021-08-17 by @gfwilliams If you start up the Puck holding BTN1 down then it shouldn't run any code whatsoever and will also clear out any saved pairings. At that point you should be able to connect and run Posted at 2021-08-20 by user130485 it does not seem to be RAM related. I set it to reboot every night but having an issue with it getting stuck due to the stupid LED light on the meter staying on and somehow making LDR to cause the puck to hang after a while Posted at 2021-08-20 by @gfwilliams Is it possible that you've just got an almost flat battery? If you did then the increased power draw from the LDR when the light was on would drop the voltage so much that the Puck stopped working? Posted at 2021-08-20 by user130485 thought so too but it's only 2 days since I put a fresh battery in. After I removed puck from the meter box and stuck LED (which was not really stuck and went off after about 10 sec) puck started working again and I was able to see/connect to it without removing the battery. When I could connect, battery was showing 50% and went up to 60% a bit later on Posted at 2021-08-30 by user130485 I am giving up on Puck =( Posted at 2021-08-31 by @gfwilliams Hi, Sorry about that. Honestly I'm not sure what to suggest - that system has been working for months here just fine. Only thing is, is it possible that some other device is trying to connect to the Puck? Posted at 2021-08-31 by @allObjects @user130485 I assume you are talking about the DiY Smart Meter from https://www.espruino.com/Smart+Meter - and - some additional code and wiring (or BLE), that talks to the ESP32. My initial thought was that on uploading the code and on start up / init, something must fall between the cracks - not clean setup with all in onInit(), or in cooperation with the other device something with the sequencing creates an issue. Looking at the example, all happens in onInit() (at least what the espruino example shows... except the creation of the Counter). A last ditch effort could be in taking a more subtile approach on detecting a pulse of the meter LED. In a nutshell: have a state machine that uses falling as well as rising non-repeat watches and monitors the state changes with additional, separate timeouts. This would allow to detect meter's LED staying on too long for being counted as a pulse for counting (on because the is busy with communication... which also throws a shadow on the accuracy of the setup of counting blinks). An additional option is to control the 'powering' of the LDR: set D1 high to end a stuck cycle. After a power-meter-LED-on-for-too-long cycle, I assume, the power meter returns to normal blinking. Posted at 2021-08-31 by user130485 Yes, it was based on the Smart Meter but with a heap of extra code to optimise it for my situation. ESP32 is just a BLE receiver that sends the data to Home Assistant. Posted at 2021-08-31 by user130485 I have uploaded the full code to pastebin, if someone interested Posted at 2021-08-31 by @gfwilliams Thanks - looking at the code, you do stop it sending its name over Bluetooth. Usually that would be ok and you would just see the MAC address but in order to find it the IDE then uses scan response data, which can be a bit unreliable if there is a bunch of Bluetooth traffic. I guess that could be it? When you can't connect, can you still see it advertising with the NRF Connect app? One way to debug is to add a USB-TTL adaptor so you can always communicate with it regardless of Bluetooth state. That really increases power draw though (1mA) so it's something you'd only do for debugging. One other thing is you could add a watchdog timer. It's super unlikely that you would ever have a lockup, but at least if you do add the watchdog timer you could rule that out Posted at 2021-08-31 by user130485 Thank you @gfwilliams for helping me out =) Posted at 2021-08-31 by @gfwilliams No problem! If you need it, the connections are at http://www.espruino.com/Puck.js#serial-console For the watchdog timer you just need http://www.espruino.com/Reference#l_E_enableWatchdog So if you do You can go one step further and manually poke it in your code, so you know that if your code doesn't execute that line in X seconds the device reboots:
You just need to watch out that if you go to update the firmware the watchdog will still be running and may cause a reboot if it isn't enabled in the new bit of code you update. As I said above though, one reason you may not see it advertising is if some other device has automatically connected to it. You could always add Posted at 2021-08-31 by @allObjects @user130485 downloaded your code and gave my understanding of it a shot... Three things that bothers me about the code are:
And there is a 4th thing - not really adding to the code - is the source formatting... if it is structurally off, I get mislead in the logic... So my first action was to adjust it to support my (human) reading abilities and my understanding what happens when and in what relation to other sections of the code. Regarding code design: Intervalled code is fine if it does not interfere with state. (Sure one can have gazillions of synchronization flags / semaphores, but that does make the code not more robust or components more loosely coupled). Posted at 2021-08-31 by user130485 was not meant to be a production code =) just something I was putting together for myself Posted at 2021-08-31 by user130485 thank you again @gfwilliams! Posted at 2021-09-01 by @gfwilliams
Yes, that's correct. The getting stuck with prints is an issue for USB devices if they're plugged into a PC but nothing is reading data - but it shouldn't apply to bluetooth |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2021-08-16 by user130485
Hello
I had my puck running for 3 days without an issue as a power meter.
But then it stopped reading the data as a power meter and I can no longer connect to it.
It still sends current battery and temp statuses.
When I try to connect to it I get this:
Beta Was this translation helpful? Give feedback.
All reactions