Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:16 11 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : ESP8266 with PIC32MX, TCP open issue

Author Message
rallyman
Newbie

Joined: 15/02/2017
Location: Hungary
Posts: 9
Posted: 07:25am 11 Mar 2017
Copy link to clipboard 
Print this post

Hello Guys,

First of all, thanks your help with my pir sensors last time.
Now I go further with my project and try to settle up an ESP8266 wifi connection, but I have some issues...

Let's see the topology:
- PIC32MX170256D
- ESP8266-01

I have also gone throuhg the panel draws, I have found TX/RX pins on my PIC. I use UART2 to connect the ESP through serial to the PIC. ON my PIC32 PIN6-7 is for TX/RX, it is connected fine, I can communicate with the ESP through the PIC. I use 3.3V for the ESP getting out it from the PIC. I have also get out the GND from the PIC.

my idea is:
- power on the pic
- burn the MMBASIC code via usb (uart1)
/the code will do/
- use some AT commands to attach the ESP to my wifi-router (SSID, psw) (linksys wrt)
(IP gets via DHCP, but I also set up a static arp in the router to get always the same IP address about some debug purposes)
- with AT commands, open a tcp session to my home-server (apache port 8080)
- send some charachter (in my example HTTP GET, in the fure I will call a php url)

my expereinces:
Webserver is running fine (apache, mysql also), I can reach it via other pc-s in web and cli(ssh). When I start my MMBASIC program with my PIC+ESP setup, it can connect the wifi LAN, it gets the IP address via DHCP. I run a continious ping to that IP, and it starts reply when the ESP connects to the wifi-rtr. IP connection works perfect.
After that I try to open the TCP session to my server and there comes the issue... I also run a whireshark on my server and there is no incoming packets ever. In the debug of MMBASIC, I can see there is a "busy" message after the AT+CIPSTART line...

I tried to figure out it is an ESP or PIC issue. If I connect the ESP directly to my pc via serial usb uart converter modul, I can use 'putty' or 'termite' program and I can communicate with AT commands perfetly and I also see the incoming session in my whireshark log.

But, unf. when I connect the ESP back to the PIC, it start, can connect to wifi, it is pingable, but cannot open the TCP session, because of "busy"...

1. pict: direct connection ESP_to_PC, manual send AT commands via termite
2. pict: ESP is connected via the PIC32, commands send by MMBASIC code, no any incoming tcp session from the ESP to the server.








Here is my SUB for the connection. Please be aware that I have to use CHR(34) instead of the charachter (") and I also have to take care of \r\n (CR,LF) charachters.



dim string CRLF=chr$(13)+chr$(10) length 2

SUB open_tcp

'local strings
LOCAL dat AS STRING
LOCAL ssid AS string
LOCAL pass AS STRING
LOCAL connstr AS STRING

'strings because of CHAR""
ssid$ = chr$(34) + "SURVIVOR_V3" + CHR$(34)
pass$ = CHR$(34) + "surV1V0R" + CHR$(34)
connstr$ = CHR$(34) + "TCP" + CHR$(34)+ ","+ CHR$(34) + "192.168.222.101" + CHR$(34) + ",8080"

'open com1
OPEN "COM1:115200,4096" AS #5
pause 300
PRINT #5, CRLF
PRINT #5, CRLF
PAUSE 300

PRINT #5, "AT+RST"
PRINT #5, CRLF
PRINT ">>>>>>>> ESP reset OK"

'STA mode 1
PAUSE 300
PRINT #5, "AT+CWMODE=1"
PAUSE 300

'Connect to SSID using strings decl. above
PAUSE 300
PRINT #5, "AT+CWJAP="+ssid+","+pass
PAUSE 300
PRINT ">>>>>>>> ESP Connect OK to "+ssid+" with "+pass
PAUSE 300

'single TCP/UDP session
PRINT #5, "AT+CIPMUX=0"
PAUSE 300

'open TCP session to 10.10.10.101:8080
PAUSE 300
PRINT #5, "AT+CIPSTART="+connstr
PRINT #5, chr$(13)+chr$(10)
PAUSE 500

'DAT 7. debug
dat$ = INPUT$(250, #5)
PRINT "/// DAT7 "+dat
PAUSE 200

PRINT #5, "AT+CIPCLOSE"+CRLF
PRINT ">>>>>>>> Send OK"

CLOSE #5

RETURN
END SUB




So, could someone has any idea, why I cannot connect open the TCP session with my ESP when it is connected to the PIC?

Much appreciate!
R.
 
plasma
Guru

Joined: 08/04/2012
Location: Germany
Posts: 437
Posted: 08:59pm 11 Mar 2017
Copy link to clipboard 
Print this post

try a bigger delay , i think 300 ms is to little
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 11:17pm 11 Mar 2017
Copy link to clipboard 
Print this post

Hi,

Perhaps this line

connstr$ = CHR$(34) + "TCP" + CHR$(34)+ ","+ CHR$(34) + "192.168.222.101" + CHR$(34) + ",8080"

should finish with + chr$(34)

Edit: perhaps chr$(34) either side of the 8080 (but then you don't seem to need to when typing it in directly.)
Edited by ajkw 2017-03-13
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 12:32am 12 Mar 2017
Copy link to clipboard 
Print this post

Maybe not chr$(34) around 8080

Perhaps a CR LF is needed in each of these

'STA mode 1
PAUSE 300
PRINT #5, "AT+CWMODE=1"
PAUSE 300

'Connect to SSID using strings decl. above
PAUSE 300
PRINT #5, "AT+CWJAP="+ssid+","+pass
PAUSE 300
PRINT ">>>>>>>> ESP Connect OK to "+ssid+" with "+pass
PAUSE 300

'single TCP/UDP session
PRINT #5, "AT+CIPMUX=0"
PAUSE 300
 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 06:11pm 17 Mar 2017
Copy link to clipboard 
Print this post

BECAUSE,

At the end of each Print command MMBasic sends it own CR LF

so

PRINT #5, "AT" + chr$(13) + chr$(10)

sends AT CR LF CR LF

and that triggers the Module to reply with busy p...

so

use a semi colon (and MMBasic will suppress its own CR LF)

PRINT #5, "AT" + chr$(13) + chr$(10);

or of course just

PRINT #5, "AT"

to send AT CR LF and get a happy response from the module.






Edited by ajkw 2017-03-19
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024