Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:20 01 Aug 2025 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 : Can't get WiFi TCP/IP client working

Author Message
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 05:29pm 13 Jan 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4044
Posted: 05:36pm 13 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 05:44pm 13 Jan 2021
Copy link to clipboard 
Print this post

Ah, excellent! Thanks!
-Bill
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 05:57pm 13 Jan 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10310
Posted: 08:03pm 13 Jan 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 6283
Posted: 08:26pm 13 Jan 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4044
Posted: 10:24am 14 Jan 2021
Copy link to clipboard 
Print this post

  William Leue said  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

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: Australia
Posts: 6283
Posted: 11:13am 14 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 104
Posted: 11:16am 14 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 12:29pm 14 Jan 2021
Copy link to clipboard 
Print this post

Ok thanks, I will look for the Zimodem stuff.

-Bill
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 02:24pm 14 Jan 2021
Copy link to clipboard 
Print this post

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: Australia
Posts: 6283
Posted: 08:45pm 14 Jan 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 07:50pm 15 Jan 2021
Copy link to clipboard 
Print this post

Thanks, Jim!
-Bill
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025