I have red through some posts but could not find one similar in cause to this. I know it is not the Interrupt pin itself causing trouble as I have used it before, but probably the way it is implemented in my code
When I uncomment the following lines, it causes solid RED led as soon as I trigger D7 which is opening the relay. the device then disconnects and can only be restored by manually turning the power off/on.
pinMode(A2, INPUT); //Interrupt pin - 4k7 series resistor CURRENTLY RESULTS IN HARD FAULT
attachInterrupt(A2, Listen_Mode, FALLING);
The Listen mode is fairly simple;
void Listen_Mode() { // Enter Listem mode when interupt is called
WiFi.listen();
}
I have no idea where the problem lies, but as soon as I disable the Interrupt by commenting out either of the two lines, the device works as expected.
ps: I know I still need to write a function for the two startup commands as this is not ideal, but I have disable one and it has no affect.
Sorry if I am getting this wring still, but I have implemented some code in the following way as I am not sure how to implement
So I created:
void Listen_Mode() { // Enter Listem mode when interupt is called
int Atwo = analogRead(A2);
if (Atwo < 50)
WiFi.listen();
Particle.publish("A-two", String(Atwo), PRIVATE); // debug
I have commented out the Interrupt section but here lies my problem. It seems if BLYNK does not authenticate with this server, it blocks the rest of the code from running. Which leads me to a problem I had before when attempting all of this with code;
If the device has connected successfully and thereafter it gets disconnected, the Listen_Mode implementation works like a charm. IF however the device has been powered down or restarts and cannot connect to WiFi... It never enters the loop, despite of SYSTEM_MODE(SEMI_AUTOMATIC);. I do not have threads enabled. I tried it, but had some undesired 'consequences'
I will try to figure out how to proceed and would appreciate some further advice if you can spare the time.
You must avoid calling any Blynk stuff as long you have not established at least a WiFi connection otherwise these calls will fail - often note gracefully.
void loop() {
Blynk.run();
CS();
temperature();
connect();
Listen_Mode();
}
void Set_Listen_ModeFlag() { // Set Listen mode FLAG = true
Listen_ModeFlag = true;
}
void Listen_Mode() { // Enter Listen mode
if (Listen_ModeFlag == true) {
WiFi.listen();
}
}
As far as I can tell, the loop is now handling the entering to Listen mode part??
I tested on a breadboard version, seems ok except for a hard fault each time it exists listing mode, but it corrects and then connects to Particle Cloud. Of course I will need to test it on an actual unit with all the bells and whistles, will do this in the morning. Also still need to test if it still works when the unit starts up without connecting to WiFi at all.
Your Listen_ModeFlag needs to be volatile and you should put Bynk.run() in a if (WiFi.ready()) block.
You also want to reset Listen_ModeFlag before you call WiFi.listen() in order to not fall back into it once you came out.
On this... I got severely reprimanded on there BLYNK forum for what they see as a non-empty void loop(). After this, I decided to keep it as 'clean' as possible
I will try to implement, than you for your patience
No idea how they would argue a āreprimandā for a non-empty loop().
Would they expect your code to run nothing but their Blynk stuff? That doesnāt make sense.
Have you got a link to that thread?
If their logic would be resilient against lack of a valid connection you could probably get away without the WiFi.ready()-check but IIRC their library is not.
I once also had some discussion about style reagarding some of their functions require non-const parameters where there would definetly (IMHO) be call for const but they refused to consider the proposal entirely
Hence Iām somewhat reluctant to just take their word for it
I will check if I still have the link. I rarely get annoyed with people online, but I did not have a great experience in the forum at all. They seem quite set in their ways and believe nothing else can work. they had an issue as I had a 1 second delay in my loop.
Here is what I have so farā¦ the only way I could get Blynk to authenticate without having the call in void setup()
You may still want a waitFor(WiFi.ready, someTimeout) between the Particle.connect() call and Blynk.begin(auth).
like so
WiFi.connect();
if (waitFor(WiFi.ready, 60000)) {
Blynk.begin(auth);
Particle.connect();
connectToCloud = false;
}
else {
// take some action to deal with missing WiFi connection
}
BTW, you are negating the WiFi.ready() check here, but you want Blynk.run() to be called only when this is true
Ok, so after hours and hours of trying to figure this out, I decide to try a more simplistic approach with a small āillegalā sketch on a breadboard, calling Listen mode directly from a ISR. Seems to work. :). I then loaded this onto a device and the error started again.
I then replace listen mode with simple LED high when A2 is called and you wont believe itā¦ it is called even when I trigger D7 HIGH
I have gone through the schematic endless times and cannot seem how in the world D7 and A2 would be connected. I will assemble a new unit today and incrementally test to see when the problem occurs.