Catus Micro r2 socket server

#1

Hello, again.
Second trial, I made tcp/ip socket server with Catus Micro r2.
The message from client is received as expected but it was not possible to send message from Cactus server.
Again, I only see "Busy s…"
It would be really helpful if you give me some advice.
Here are full source code and serial output

Source

#include <avr/pgmspace.h>

#define WIFI_ENABLE_PIN 13
#define DEBUG true

#define SSID "ssid"      //your wifi ssid here
#define PASS "passwod"   //your wifi wep key here

void setup()
{
  Serial1.begin(9600);
  Serial1.setTimeout(10000);
  Serial.begin(9600);  //can't be faster than 19200 for softserial

  if(DEBUG) {  
    while(!Serial);
  }

  pinMode(WIFI_ENABLE_PIN, OUTPUT);
  digitalWrite(WIFI_ENABLE_PIN, HIGH);

  sendData("AT+CWMODE=1",5000);
  sendData("AT+CIPMUX=1",5000);
  sendData("AT+CIPSERVER=1", 5000);
  sendData("AT+CIFSR",5000);
    
  Serial.println( "Start Socket server 31" );
  
}

void loop() {
  delay(5000);
  clearRx();
  sendData("AT+CIPSEND=0,4",6000);
  delay(1000);
  sendData("iopd",6000);
  delay(1000);
}

void clearRx() {
  while(Serial1.available() > 0) {
    Serial1.read();
  } 
}


String sendData(String command, const int timeout)
{
  String response = "";
  Serial1.println(command); // send the read character to the esp8266
  long int time = millis();
  while( (time+timeout) > millis()) {
    while(Serial1.available()) {
      // The esp has data so display its output to the serial window 
      char c = Serial1.read(); // read the next character.
      response+=c;
    }  
  }
  if(DEBUG)  {
    Serial.print(response);
  }
  return response;
}

Serial output

AT+CIPMUX=1


OK
AT+CIPSERVER=1


OK
AT+CIFSR

+CIFSR:STAIP,"192.168.0.23"
+CIFSR:STAMAC,"18:fe:34:f2:93:2d"

OK
Start Socket server 31
AT+CIPSEND=0,4


OK
> 
+IPD,0,20:Hello! from client
iopd
busy s...

SEND OK
AT+CIPSEND=0,4


OK
> iopd
busy s...

SEND OK
AT+CIPSEND=0,4


OK
>
针对 Cactus Micro and Arduino 不能使用 设置SERVER模式吗?
#2

You need upgrade the AT firmware to newer to avoid the issue. Here’s a wiki for how to re-program the esp-03 module on Cactus Micro.

The v1.1.1 firmware for esp-03

Cactus WIFI server only serves page once, sometimes twice
#3

Can you explain how to do firmware upgrade?
I tried 5 firmwares for ESP8266. but all of them was not work. All AT command returns strange chracters.

NODEMCU FIRMWARE PROGRAMMER settings

Config: ai-thinker-v1.1.1.bin 0x00000
Advanced: Baudrate 115200, Flash size 4MByte, Flash speed 40Mhz, SPI Mode DIO

After upgraded to new firmware, ESP8266 does not response properly.

AT
Read serial1=> �
 fail!

searchBaudRate.ino returns

ESP baud rate is: not found.

I tried baud rate of Serial1 115200 and 9600 but they are not printing response correctly.

I was not able to try flash firmware with ‘modified version esptool’ but if you tell me how to do it from OSX with esptool. I will love to try.

#4

Please change the SPI Mode to QIO. The AT command must end with “\r\n”. So if you want to test the AT command. Use the code:

Serial1.print("AT+GMR\r\n");

The hardwareSerialMonitor sketch will not work.

#5

Thanks for follow up comment
AT command seems working ok but I cannot read the result from ESP8266. I think this is related to your last comment hardwareSerialMonitor will not work.
How can I read character from ESP8266 correctly?

Test Code

#include <avr/pgmspace.h>

#define DELAY_PERIOD 10000
#define WIFI_ENABLE_PIN 13
#define DEBUG true

void setup()
{
  Serial1.begin(115200);
  Serial1.setTimeout(10000);
  Serial.begin(115200);  //can't be faster than 19200 for softserial
  if(DEBUG) {  
    while(!Serial);
  }
  pinMode(WIFI_ENABLE_PIN, OUTPUT);
  digitalWrite(WIFI_ENABLE_PIN, HIGH);
  delay(1000);

  Serial.println( "Start" );
}

void loop() {
  Serial.println( "loop1" );
  Serial1.print("AT+GMR\r\n");
  delay(1000);

  while ( Serial1.available() ) {
    Serial.write(Serial1.read());
  }  
  Serial.println();

  delay(5000);
  Serial.println( "loop2" );
  Serial1.print("AT\r\n");
  delay(1000);

  while ( Serial1.available() ) {
    Serial.write(Serial1.read());
  }  
  Serial.println();

  delay(5000);
}

Result

loop2
AU¨
C¡j5

loop1
AÕé5RCHA²•r®ë¹:r2M	r0IÕn5’0LŠ6'º:LS©
*Ô
²•r®ë¹:L)r1C¡¥-+¹kY
loop2
AU¨
C¡j5

loop1
AÕé5RCHA²•r®ë¹:r2M	r0IÕn5’0LŠ6'º:LS©
*Ô
²•r®ë¹:L)r1C¡¥-+¹ëY
loop2
AU¨
C¡j5

loop1
AÕé5RCHA²•r®ë¹:r2M	r0IÕn5’0LŠ6'º:LS©
*Ô
²•r®ë¹:L)r1C¡¥-+¹kY
loop2
AU¨
C¡j5

loop1
AÕé5RCHA²•r®ë¹:r2M	r0IÕn5’0LŠ6'º:LS©
*Ô
²•r®ë¹:L)r1C¡¥-+¹kY
loop2
AU¨
C¡j5

loop1
AÕé5RCHA²•r®ë¹:r2M	r0IÕn5’0LŠ6'º:LS©
*Ô
²•r®ë¹:L)r1C¡¥-+¹kY
loop2
#6

It will work if you change the baud rate to 9600. Follow the steps:

  • Get the sketch hardwareSerialMonitor

  • Change the line #define BAUD_RATE 9600 to #define BAUD_RATE 115000

  • Upload the sketch to Cactus Micro

  • Open the Serial Monitor, you will see some chars can’t read by human.

  • Just type the AT command “AT+UART=9600,8,1,0,0”

  • It will not response to any other input now. Restore the hardwareSerialMonitor sketch, change 115000 -> 9600

  • Re-upload the sketch

  • It should work now

Cactus Micro Rev 2 + WifiConnection + PIR Probelm
#7

I have tried the newest at firmware v1.4 from espressif. It also work with the method. But you need change the baud rate by “AT+UART_DEF”

#8

I really appreciate your help.
That works perfectly.
Thank you.