Send gcode via ESP32 to Duet wifi.
-
Thank you very much!!!!
-
simple ESP32 code to send g-code to duet
#include <WiFi.h> #include <WiFiClient.h> #include <ESPmDNS.h> const int led = 5; const char* ssid = "ccc"; const char* password = "pass"; //const char* host = "192.168.1.115"; const char* host = "ender5.local.lan"; const int port = 23; int l = 0; int potValue = 0; WiFiClient client; int sendGcode(char * gcode){ unsigned long timeout; int ret; ret = 1; client.print( String(gcode) + "\r\n" ); timeout = millis(); while (client.available() == 0) { if (millis() - timeout > 5000) break; } while(client.available()) { String line = client.readStringUntil('\r'); Serial.print(line); if (line.startsWith("ok")) ret = 0; if (line.startsWith("\nok")) ret = 0; if (line.startsWith("\r\nok")) ret = 0; } return(ret); } void setup() { pinMode(led, OUTPUT); digitalWrite(led, 0); Serial.begin(115200); delay(10); Serial.print("Connecting to "); Serial.println(ssid); WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.mode(WIFI_AP); if (MDNS.begin("pendantDue")) { Serial.println("MDNS responder started"); } WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); delay(1000); Serial.print("connecting to "); Serial.print(host); Serial.print(":"); Serial.println(port); if (!client.connect(host, port)) { Serial.println("connection failed"); while(1){ digitalWrite(led, 0); delay(500); digitalWrite(led, 1); delay(500); } return; } Serial.print("CONNECTED to "); Serial.print(host); Serial.print(":"); Serial.println(port); } void loop() { delay(5000); sendGcode("M115"); }
-
@smece thx a lot.. that really saves me from wandering through github and places in the internet where my mind is not suited for. ^^ (smece-- funny name. means garbage in croatian language)
-
@flipil said in Send gcode via ESP32 to Duet wifi.:
smece-- funny name. means garbage in croatian language)
znaΔi i kod nas na istoku
thx a lot.. that really saves me from wandering
you are welcome, I started making a pendant for duet with esp32 so that's the initial test how to talk to it
note that if you don't close the connection
client.stop();
it can "block" as it looks like duet is listening only with one or two threads ... you might want to change to open connection to send gcode and immediately close if you don't plan to send many commads -
Hvala ti puno smece spasio si mi zivot.
-
@bearer said in Send gcode via ESP32 to Duet wifi.:
But instead of HTTP requests you can enable telnet and connect to the telnet port and send GCODE directly instead of dealing with the DWC API
Just note for the future: Telnet is going away in Duet/RepRap V3 firmware.
For that matter, so are RR_whatever HTTP calls. Moving to websocket.
-
@Danal said in Send gcode via ESP32 to Duet wifi.:
For that matter, so are RR_whatever HTTP calls. Moving to websocket.
WHY oh WHY ?!
adding websocket is ok, but removing telnet ?!?!?! why ?
-
That was pretty much my question to DC42. Perhaps if we both asked nicely, he'd reconsider.
-
@Danal @smece on Duet 3 you have all the connection options of whatever SBC you use. So SSH into it if you wish.
-
@T3P3Tony said in Send gcode via ESP32 to Duet wifi.:
@Danal @smece on Duet 3 you have all the connection options of whatever SBC you use. So SSH into it if you wish.
so telnet is not going away?
-
@smece said in Send gcode via ESP32 to Duet wifi.:
so telnet is not going away?
with respect to Duet 3 + SBC telnet is already gone, unless you cobble together something like socat and the command line client
-
@bearer said in Send gcode via ESP32 to Duet wifi.:
with respect to Duet 3 + SBC telnet is already gone
dunno what's SBC but I'm running RRF3 on Duet2Eth and telnet is still here
-
@smece said in Send gcode via ESP32 to Duet wifi.:
dunno what's SBC but I'm running RRF3 on Duet2Eth and telnet is still here
Duet 3 as in 3rd generation hardware not firmware, and SBC refers to a single board computer like the raspberry pi.
-
@bearer said in Send gcode via ESP32 to Duet wifi.:
Duet 3 as in 3rd generation hardware not firmware
Yes, of course, but it's firmware that's handling telnet server, and I find it weird that same version RRF3 for duet3 and duet2 is different in that regard.
SBC refers to a single board computer
thanks
-
@smece said in Send gcode via ESP32 to Duet wifi.:
and I find it weird that same version RRF3 for duet3 and duet2 is different in that regard.
the difference is when used with the single board computer the Duet doesn't use the ethernet interface, only SPI; ergo Telnet is not an option any more as its not supportd by the software package for the SBC.
(although i havent tested it in stand alone operation if it still support telnet)
-
@bearer said in Send gcode via ESP32 to Duet wifi.:
the difference is when used with the single board computer the Duet doesn't use the ethernet interface, only SPI;
makes sense to disable ETH if the communication is moved to SBC .. but then you can telnet to SBC so it's still available
-
@bearer my point was with the SBC you can connect over SSH (i.e. secure telnet) that drops you into the console on the SBC where you can use a tool like CodeConsole to send gcode to The Duet.
So no you are not Telneting directly into the Duet but you have the potential for command line gcode entry.
Of course if you want telnetd specifically (as opposed to sshd) the. You can install telnet on the SBC. Presumably this would only be to connect from clients that don't support SSH?
-
@smece said in Send gcode via ESP32 to Duet wifi.:
but then you can telnet to SBC so it's still available
yes, but no-ish. to get the same functionality to send g-code directly to the socket you'll need some DIY stuff ala socat
@T3P3Tony said in Send gcode via ESP32 to Duet wifi.:
So no you are not Telneting directly into the Duet but you have the potential for command line gcode entry.
same as above, it'll break something like an ESP8266 client sending g-code, unless you sprinkle some 11 spice and herbs on it or adapt the client. not saying its a problem, just pointing out the difference between telnet with a linux shell and telnet to todays Duet2.
(Edit: If the client support SSH (which rules out the tiniest embedded systems due to resources needed for the encryption, i.e. same reason SSH isn't offered on the Duet2) then SSH is actually easier to combine with CodeConsole as you could pipe data directly to CodeConsole running on the remote system as opposed to telnet to a shell)
-
@bearer said in Send gcode via ESP32 to Duet wifi.:
yes, but no-ish.
yup, it is clear additional sw would be required on SBC but is doable without big rewrite of client while switching to WS would be a big rewrite
-
@Danal said in Send gcode via ESP32 to Duet wifi.:
Just note for the future: Telnet is going away in Duet/RepRap V3 firmware.
For that matter, so are RR_whatever HTTP calls. Moving to websocket.@gtj0 said in Boilerplate HTTP connection code for Python-based UI:
Wait, I may have misunderstood something. You're using RRF3 on a Duet2? If so, then the websocket won't work. That's only for a Duet3 with the Duet Software Framework on a single board computer. Sorry about that. I saw you asking about websocket and didn't read the previous posts thoroughly.
Your original approach should work fine on a Duet2 regardless of the version of RRF you're using. You don't really have to use rr_connect at all for your application.
There's an explanation of the rr_* commands at
https://github.com/chrishamm/DuetWebControl/tree/legacyDid something change, or is there a missunderstanding somewhere?