-->
Page 1 of 2

Getting strange characters; none of the suggestions work

PostPosted: Tue Apr 28, 2020 10:10 am
by JohanF
Hi!

So I have started with the ESP8266 and it's been a rough ride. Everythime when I think I have, it fails. Last thing I did was install new firmware and all of a sudden I get normal words and strange chars.

My code:

Code: Select all#include <HardwareSerial.h>
#include <SoftwareSerial.h>

SoftwareSerial esp(2, 3); // RX, TX

void setup()
{
  Serial.begin(9600);
  esp.begin(115200);
  connectoToWifi();
}

void connectoToWifi()
{
  String SSIDstring = ("\"WIFI_NAME_HERE\"");
  String PASSstring = ("\"WIFI_PASSWORD_HERE\"");
 
  sendData("AT+RST\r\n", 1000, true);
  sendData("AT+CWMODE=1\r\n", 500, true);
  sendData("AT+CWJAP=" + SSIDstring + "," + PASSstring + "\r\n", 5000, true);
  sendData("AT+CIPSTATUS\r\n", 500, true);
  sendData("AT+CIFSR\r\n", 500, true);
  sendData("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",80\"", 500, true);
}

String sendData(String command, const int timeout, boolean debug)
{
  String response = "";
  esp.print(command); // Stuur een "lees" karakter naar de ESP.
  long int time = millis();
  while ((time + timeout) > millis())
  {
    while (esp.available())
    {                 
      char c = esp.read(); // Lees het volgende karakter.
      response += c;
    }
  }

  if (debug)
  {
    Serial.println(response);
  }
  return response;
}

void loop()
{
 
}


In my Serial monitor I see something like this:

Image

I found this topic: viewtopic.php?f=32&t=2664&hilit=+coolterm

But it didn't fix it for me. I also tried like 30 other suggestions, but none seem to work. A few that keep coming back:

- Flash it (did that like 6 times)
- Change the baudrate of the esp (very popular)
- Check the connections
- Reset it, flash it, change baudrate

What am I missing here?

Re: Getting strange characters; none of the suggestions work

PostPosted: Wed Apr 29, 2020 8:01 am
by QuickFix
What are you trying to achieve?
GPIO1 and GPIO3 are already the (hardware) TX and RX serial pins respectively, you can use them directly without using soft-serial.
If you assign GPIO3 (hardware RX) to software serial, you'll be getting conflicts.

If you actually do need 2 serial ports, you'd better use GPIO1 and/or GPIO3 as hardware ports (or swap them so hardware serial is on GPIO15 and GPIO13) and use software serial on any other non-conflicting GPIO's (please note that some GPIO's might have restrictions, like GPIO0, GPIO2 and GPIO15 that need a certain state to properly boot the ESP).

See more about the ESP's serial ports here.

I'm not entirely sure I understand your code: are you trying to connect to another ESP running AT firmware to talk to ThingSpeak?
Wouldn't it be easier to directly do this from code, without using a proxy ESP and shitty AT commands?

Volgens mij zit je veel moeilijk te denken. :?

Re: Getting strange characters; none of the suggestions work

PostPosted: Thu Apr 30, 2020 6:44 am
by JohanF
QuickFix wrote:What are you trying to achieve?
GPIO1 and GPIO3 are already the (hardware) TX and RX serial pins respectively, you can use them directly without using soft-serial.
If you assign GPIO3 (hardware RX) to software serial, you'll be getting conflicts.

If you actually do need 2 serial ports, you'd better use GPIO1 and/or GPIO3 as hardware ports (or swap them so hardware serial is on GPIO15 and GPIO13) and use software serial on any other non-conflicting GPIO's (please note that some GPIO's might have restrictions, like GPIO0, GPIO2 and GPIO15 that need a certain state to properly boot the ESP).

See more about the ESP's serial ports here.

I'm not entirely sure I understand your code: are you trying to connect to another ESP running AT firmware to talk to ThingSpeak?
Wouldn't it be easier to directly do this from code, without using a proxy ESP and shitty AT commands?

Volgens mij zit je veel moeilijk te denken. :?


What I am trying to achieve is that my esp8266 is posting some data to an API. I have an API, which works. Due to company information, I cannot share this URL and data.

So, in short:

- Arduino gets data from a sensor
- This data should be send to an API by the esp8266 unit

Does this help?

Misschien wel, maar wellicht is dit de ervaring (die er nog niets is) en de vele manieren en vele tutorials op internet.

Re: Getting strange characters; none of the suggestions work

PostPosted: Thu Apr 30, 2020 10:59 am
by AcmeUK
- Arduino gets data from a sensor
- This data should be send to an API by the esp8266 unit

Is there a technical reason why you are using the Arduino?

A suitable esp8266 like the NodeMCU has plenty of capacity to read sensors and send the data to an API.

There is a multitude of example scripts on the net.

Trying to use the AT commands invites a whole lot of headache!