electronicsguy / ESP8266

ESP8266 Projects
242 stars 183 forks source link

Doesn't connect to scripts.google.com when setting an IO pin as output. #77

Closed Istria1704 closed 5 years ago

Istria1704 commented 5 years ago

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:

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().

Istria1704 commented 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.

  1. Keeps trying to connect for 5 times, then proceeds without connection. (10%)
  2. Tries connecting for a while. Succeeds on second of third try. (10%)
  3. Connects almost instantly. This happens most of the time (80%).

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?

brianmwebb commented 5 years ago

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...

jnevinger commented 5 years ago

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

jnevinger commented 5 years ago

Nevermind.

I got it.

electronicsguy commented 5 years ago

@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.