Closed Istria1704 closed 5 years ago
Update. I tested the device I made in the field yesterday. The not-connecting issue still happened sometimes. It always connects to the WiFi perfectly and quickly.
When it starts connecting to the host (in setup()), one of three things happen.
I could not find any logic in it. Same WiFi, same signal, same wiring. Just removing and restoring power would change the behaviour. Usually it works perfectly.
Thing to note is, that when it happens that it won't connect, resetting the ESP8266 does not fix it immediately. It will hang the second time as well. Trying again after a couple of minutes fixes it usually.
Any thoughts?
Similar problems with my own script The sample script is also failing similarly, had been working OK x2d csum 0x2d v21db8fc9 ~ld Free heap: 49432 Free stack: 3900
Connecting to wifi: BMW ..... WiFi connected IP address: 192.168.0.115 Connecting to script.google.com Connection failed. Retrying... Connection failed. Retrying... Connection failed. Retrying... Connection failed. Retrying...
I have the sample code running.
I want to use the value that I pull from the spreadsheet instead of just printing to serial port. It prints to serial port fine.
I changed: client->setPrintResponseBody(false);
I need help with the format for:
_**If the request was successful, the endpoint response can be obtained as a string using the method:
String getResponseBody(void);**_
I very weak at coding so please go easy on me and don't assume I know anything. HaHa
Nevermind.
I got it.
@jnevinger Glad you got it working!
"I could not find any logic in it. Same WiFi, same signal, same wiring." - unfortunately, this is out of my hands. esp8266 wifi stack and wificlient handle this part, and given the nature of IoT devices, it's not always robust. Please tinker around with it more and if you find something solid, we can include it here.
FINAL EDIT: I thought of deleting my original text, since it got a bit messy. But thought why not leave it for context if needed.
Summarized, I had the following problem:
GoogleDocs example works out of the box, still not sure how exactly though.
First, I tried slimming it down to my minimal needs (posting 1 value to a sheet when a function is called). When that still worked, I copied it all over to my existing (also working) program that controls the GPIOs running a PLC like loop. Suddenly, it would not connect to the host anymore. Retries for 5 times and then continues (without success). Then, I tried it the other way around. Copying my existing program to the working HTTPS Redirect program. Same issue.
Then, I tried adding parts of code and testing it, step by step. I found out that without the pinMode part, it would connect. And with it, it wouldn't. After fiddling around, replacing the pin variable names by actual GPIO numbers, it started working (connecting to host) with all pinModes set.
Then, when I added my void(loop), again it would not connect anymore at setup. Commenting out a part of it solved it. And after uncommenting it right afterwards, it still worked.
So now it basically does what I need it to do and works perfectly. I just have no idea how and why it didn't want to connect before. Specifically how setting the pinModes interfered with the connection before (and doesnt anymore). And how stuff in my void(loop) could have effected connecting to the host in void(setup).
Current (working) code: https://pastebin.com/pXZv68VK Previous code that didnt connect with pinModes set: https://pastebin.com/tswDwZJD Thanks in advance for your input. As said before, the part below is the same, but less structured. Just for reference.
_____-
Hi, Nice work!
I have the thing working by itself. The weird thing is that when I implemented it into my own code, it would keep trying to (re)connect to the script.google.com host at setup().
I traced it back to the pinModes.
` // Pinmodes pinMode(scale_serial_tx_pin, OUTPUT);
pinMode(scale_serial_rx_pin, INPUT);
//pinMode(cw1_speedA_pin, OUTPUT);
//pinMode(cw2_speedA_pin, OUTPUT);
//pinMode(cw1_motorDIR_pin, OUTPUT);
//pinMode(cw2_motorDIR_pin, OUTPUT);
pinMode(sensor1_pin, INPUT);
pinMode(sensor2_pin, INPUT);`
When I uncomment one of those four, the esp8266 just keeps trying to reconnect without success at setup(). Any idea what could be the case? The pins are GPIO 0, 2, 4 and 12.
Whole code:
https://pastebin.com/tswDwZJD
Any idea what could be the case? Thanks in advance!
Marko
EDIT: The more I tinker with it, the more confused I get. I got past the pinModes by using the actual GPIO numbers: pinMode(0, OUTPUT).
But now the same thing happens with another part of code.
In my void loop(), there are 4 functions: readInputs(); checkStep(); Actions(); writeOutputs();
it works like this: readInputs(); //checkStep(); //Actions(); //writeOutputs();
it does not work like this: readInputs(); checkStep(); //Actions(); //writeOutputs();
The thing I dont get. This is in the void loop(). But i'm already failing at setup().