Lisp server on ESP32 error connection failed


#1

Hello

When calling the (lisp-server) from example
I always get error 'with-client ’ connection failed
Listening … is never printed

(defun lisp-server ()
  (with-client (s (ip '(192 168 0 207)) 1234)
    (print "Listening...")
    (loop
     (unless (= 0 (available s))
       (let ((line (read-line s)))
         (print line)
         (println (eval (read-from-string line)) s)))
     (delay 1000))))

where 192.168.0.207 is my laptop ip
and the telnet i do to 102.168.0.255 the (wifi-localip) result at port 1234
–> connection refused (run as admin)

any suggestion?

Kind regards,

Frank


#2

I’ve checked this example, and verified that you should be able to get it to work.

The ip address you give to the lisp-server function should be the ip address of your computer on the local network, not the ip address returned by (wifi-localip). I’ve slightly improved the example to make it easier to enter this ip address when you run the function.

I haven’t tried telnet as it’s not available on macOS, but with nc (netcat) you just specify a port to listen on, no ip address.

Let me know if you manage to get it working.


#3

Hello!

I get the exact same error

3816> (lisp-server 192 168 1 56)
[E][WiFiClient.cpp:213] connect(): lwip_connect_r: 104
Error: ‘with-client’ connection failed

I’m very new at this, so not entirely sure where to begin debugging.
I’m using uLisp ESP Version 2.4, Arduino-1.8 and it’s Espressif’s arduino-esp32 “1.0.0”


#4


The port 1234 isn’t open only port 80?


#5

Can you explain what your screenshot is showing? Is it showing it working, or not working?


#6

Hi David,

The lisp-server example, I never got it working.
I used Zenmap to scan the open ports from my ESP32
Only port 80 is open, and I don’t know why since i use 1234 like in the example.
On the Serial link screen, itt says: Listening …
With Putty or telnet i can’t connect to the ESP32
telnet 192.168.0.225 1234 gives no result
192.168.0.225 is the adress i get from the (wifi-localip) command
The lisp-server i give the IP from my laptop.

Kind regards,

Frank


#7

Might you have a firewall blocking non-standard ports such as 1234?


#8

I tryed ports <1000 too, no difference


#9

Have you tried doing:

telnet 192.168.1.56 1234

I think you should be telnetting to the lisp-server.

David


#10

this is a list of all my actions
in cmd window: esptool.py --chip ESP32 --port COM7 erase_flash
download this file https://github.com/technoblogy/ulisp-esp/blob/master/ulisp-esp.ino into the ESP32 after uncomment resetautorun

upload these defuns:

(defun ip (lis)
  (let ((x 0))
    (mapc (lambda (n) (setq x (+ (ash x 8) n))) (reverse lis))
    x))

(defun println (x s) (princ x s) (princ #\return s) (princ #\newline s))

(defun lisp-server (&rest iplist)
  (with-client (s (ip iplist) 454)
    (print "Listening...")
    (loop
     (unless (= 0 (available s))
       (let ((line (read-line s)))
         (print line)
         (println (eval (read-from-string line)) s)))
     (delay 1000))))

(defun do ()
	(wifi-connect "telenet-xxxx "xxxxxxxxxxx")
	(lisp-server 192 168 0 225))

Then (save-image 'do)

from that moment i can ping 192.168.0.225
but Zenmap can’t find an open port
So i can not connect with telnet


#11

Have you executed:

(do)

to run the list-server command? It’s not in your transcript.


#12

It is in the do definition


#13

Just to check; the command:

(lisp-server 192 168 0 225)

needs to be running, with Lisp hung up displaying:

Listening...

before you can telnet to the Lisp server, and you can’t run the telnet command from uLisp; you have to run it from your computer’s command line.


#14

I removed the (lisp-server 192 168 0 225) line from the 'do image and execute it from the serial monitor after a reset. First I check the local IP from the ESP32 => 192.168.0.225

I try (lisp-server 192 168 0 225) => nil
and (lisp-server 192 168 0 233) => nil the last one is the IP from my laptop

I can still enter lisp commands from the serial monitor


#15

Hmm i did try that before
For the moment i don’t execute do in the transcript
Since i (save-image 'do)
I understand wit resetautorun the function do will be executed after reset
so i run it by resetting the ESP32


#16

Hi David,

It became quiet on this thread.
I’m stuck here since 2018
I would like to be able to make that lisp-server running
The idea talk to a lisp-server, or let lisp-servers talk among each other looks so attractive
Always get Error: ‘with-client’ connection failed

I don’t know exactly what IP to give to the server: The one from my laptop, or the ESP own IP address when it connects to the home WiFi? I understood it should be the one from my laptop.

I also dont understand your ip function, if i translate each nuner to a byte and then put all bytes next to each other in same order, then give it to the ulisp interpreter, i get another number then the ip function provides

Why doesn’t it simply show: Listening … and then I can connect with Putty?
I dont understand the with-client function, should it wait to get connected from my laptop?
Why does it say connection failed before i can try to connect ?

Kind regards,

Frank


#17

Here’s a complete sequence that worked for me just now, using ESP uLisp 4.0b on an Adafruit ESP32 Feather:

1. Connect to your Wi-Fi with your network name and password:

> (wifi-connect "Home" "secret")
"10.0.1.49"

2. Define the lisp-server function and the utilities:

(defun ip (lis)
  (let ((x 0))
    (mapc (lambda (n) (setq x (+ (ash x 8) n))) (reverse lis))
    x))

(defun println (x s) (princ x s) (princ #\return s) (princ #\newline s))

(defun lisp-server (&rest iplist)
  (with-client (s (ip iplist) 8080)
    (print "Listening...")
    (loop
     (unless (= 0 (available s))
       (let ((line (read-line s)))
         (print line)
         (println (eval (read-from-string line)) s)))
     (delay 1000))))

Here I’ve used 8080 as the port number.

3. Discover the IP address of your remote computer

This can be the one connected to the ESP32, or any other computer on the network.

For example you can use ipconfig at the terminal:

$ ipconfig getifaddr en0
10.0.1.44

or you might need to use en1.

4. Start telnet from the terminal on your remote computer to the port you’re going to use:

$ nc -l 8080

It should hang up.

5. Run lisp-server with the IP address of the remote computer:

> (lisp-server 10 0 1 44)

"Listening..." 

If you omitted to start the telnet session in the previous step it will just return with nil.

6. Enter some Lisp

Now at the telnet session you can type:

(defun sq (x) (* x x))

and it will echo

sq

Then you can type:

(sq 123)

and it will echo

15129

To exit from the telnet session press Ctrl-Z.

In one of your posts you mentioned running lisp-server using uLisp’s autorun feature, by restarting the ESP32. That may be interfering with the Wi-Fi connection, so try following my sequence without restarting the ESP32.

Let me know how you get on!

Update: added the utilities you also need to install.


#18

Hi David,

Yes it finally works.
Thank you so much.
I installed ncat to listen to port 8080.
ncat -l 8080 did the job.

With save-image no result until now.
Then it makes not much sense to send commands over wifi, since it is still connected to the USB port.

It should be an autonomous lisp-server accessible over wifi.

I will experiment more with it.

In the end I would like to be able to send commands to one of more lisp-servers on esp processors and also let them send commands to each other.

Since this took me 4 years, … 😁

Kind regards

Frank Weytjens


#19

Glad it’s finally working!

The example is not very useful when you run telnet on your own computer, but you can also run telnet on another computer elsewhere on the network. In this case you do:

(lisp-server 10 0 1 44)

where 10.0.1.44 is the address of the remote computer. I’ve just checked that it all works.

Thanks for the feedback - I’ll update my Wi-Fi examples page with a fuller description so that hopefully it won’t take anyone else 4 years to get it working!


#20

I really just intended it as a demo, but to make it useful in the way you describe the uLisp command with-client should just wait, rather than returning with nil, if it doesn’t find the port open.

This could perhaps be handled by an additional parameter to with-client. What do you think?