![]() |
Forum Index : Microcontroller and PC projects : Can't get WiFi TCP/IP client working
Author | Message | ||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
I am hoping the hive mind can help with a problem I am having. I have a CMM2 Deluxe unit that includes an ESP8266 WiFi radio and controller. I am trying to write a simple program in MMBasic that would let me connect to a local TCP/IP server. I can open a COM1: connection to the controller, and it responds to "AT" with "OK" as it is supposed to. But things go downhill from there. All the other commands I send just return ERROR. Here is the short and simple program I wrote to test this: ' Test WiFi Client. Connect to TCP/IP server, get data ' Rev 1.0.0 William M Leue, 1/10/2021 option default integer option base 0 const DQUOTE = 34 const NETNAME$ = "xxxxxxx" const PASSWORD$ = "yyyyyyyy" const SIP$ = "192.168.1.8" const SPORT = 5678 const ENTER = 13 dim COM_PORT$ = "COM1" ' replace with COM1 or COM2 dim COM_SPEED$ = "115200" ' replace with baud rate dim CHAR_OUT$ dim CHARS_IN$ dim a = 0 dim cmd$ = "" cls open COM_PORT$+":"+COM_SPEED$+","+"256"+",get_serial_input" as #1 print "Terminal running, press ESC to exit." ' See if the WiFi controller responds cmd$ = "AT" print #1, cmd$ pause 300 ' Try to Set WiFi mode cmd$ = "AT+CWMODE=3" print #1, cmd$ pause 300 ' Try to connect to local Wifi network cmd$ = "AT+CWJAP=" + chr$(DQUOTE) + NETNAME$ + chr$(DQUOTE) cat cmd$, "," + chr$(DQUOTE) + PASSWORD$ + chr$(DQUOTE) print #1, cmd$ pause 500 ' Try to connect to local TCP/IP Server cmd$ = "AT+CIPSTART=" + chr$(DQUOTE) + "TCP" + chr$(DQUOTE) + "," cat cmd$, chr$(DQUOTE) + SIP$ + chr$(DQUOTE) + "," + str$(SPORT) print #1, cmd$ end if pause 10000 ' Try to close TCP/IP Connection cmd$ = "AT+CIPCLOSE" print #1, cmd$ pause 300 close #1 end ' ISR to get incoming data from connection sub get_serial_input CHARS_IN$ = input$(LOC(#1),#1) print CHARS_IN$; a = asc(CHARS_IN$) if a = ENTER then print "" end if end sub (I masked my local WiFi network name and password for obvious reasons.) Here is the log of the program, with the network name and password again masked. ![]() Any hints will be greatly appreciated! -Bill |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
Your print #1, cmd$ (where cmd$ is "AT") will send both CR & LF I think but your device probably only wants one of them. If you use print #1, cmd$; that will suppress both and you can add whichever you need either to cmd$ or do something like print #1, cmd$+chr$(x); where x is either 13 (for CR) or 10 (for LF). John |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Ah, excellent! Thanks! -Bill |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Well, I tried that but am still getting the same ERROR returns. I tried first with NL and then with CR but get the same problem with either. -Bill |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
What firmware is in the ESP8266? From what I remember Piotr puts something wacky on them (bulletin board?) |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
I thought he has put zimodem on to them. ATW"[SSI],[PASSWORD]" : Connects to the wireless access point with the given SSI, using the given password. ATD"[HOSTNAME]:[PORT]" : This opens a streaming connection between the terminal and the given host/port. Use "+++" to disconnect and exit back to command mode. Jim Edited 2021-01-14 06:31 by TassyJim VK7JH MMedit |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 4044 |
Please post the code (a fragment of it if it's long). (I think it's wanting CR in which case your former code would have left the LF as the first char of the next command.) John |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
try ATW That should give you a list of access-points it can see. If you are connected, ATI2 will give you the IP address assigned to it. VK7JH MMedit |
||||
frnno967 Senior Member ![]() Joined: 02/10/2020 Location: United StatesPosts: 104 |
The ESP has the Zimodem firmware, not the stock ESP firmware which supports those commands you're using. Search for Zimodem and you'll find Bo's github page detailing the commands. Jay Crutti: Ham Radio Operator, K5JCJ. Computer Enthusiast. Musician. Engineer. |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Ok thanks, I will look for the Zimodem stuff. -Bill |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Yes, I am getting a lot farther using the Zimodem commands. Not quite working yet but network connection is good, and I am working on sorting out the TCP/IP server connection. Thanks for the help! -Bill |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Once you are connected to your network, try AT&H That will download a page of help text from the internet. I have found a problem with the zimodem time commands. Setting your time format to 24 hour instead of 12 hour offsets the time by one hour. I can see what I think is the problem in the source code but need to watch what happens over UTC midnight before reporting the issue. It doesn't have any effect on the usability of zimodem Jim VK7JH MMedit |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Thanks, Jim! -Bill |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |