chilipeppr / serial-port-json-server

Serial Port JSON Server is a websocket server for your serial devices. It compiles to a binary for Windows, Mac, Linux, Raspberry Pi, or BeagleBone Black that lets you communicate with your serial port from a web application. This enables web apps to be written that can communicate with your local serial device such as an Arduino, CNC controller, or any device that communicates over the serial port.
http://chilipeppr.com
GNU General Public License v2.0
322 stars 101 forks source link

Send commands from RPI #51

Open ameennihad opened 6 years ago

ameennihad commented 6 years ago

I have a typical setup of tinyg and Rasberry PI running SPJS, my computer is few meters away from my CNC machine, sometimes I need to adjust XTZ and zero the machine when I'm near it without going beck and forth to the computer, what is the possibility of doing that from keyboard or game controller connected to RPI? Or possibly few buttons connected to GPIO pins?

I'm thinking of writing Python script to send command to SPJS.

Any better ideas?

chilipeppr commented 6 years ago

Watch my video on YouTube of esp32 joystick for chilipeppr. It connects in over websocket to send additional commands in.

On Mon, May 21, 2018, 2:04 PM ameennihad notifications@github.com wrote:

I have a typical setup of tinyg and Rasberry PI running SPJS, my computer is few meters away from my CNC machine, sometimes I need to adjust XTZ and zero the machine when I'm near it without going beck and forth to the computer, what is the possibility of doing that from keyboard or game controller connected to RPI? Or possibly few buttons connected to GPIO pins?

I'm thinking of writing Python script to send command to SPJS.

Any better ideas?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/chilipeppr/serial-port-json-server/issues/51, or mute the thread https://github.com/notifications/unsubscribe-auth/AHidbeaCTeh1OrS5U8Qx0_WiRNvr7pKjks5t0yv7gaJpZM4UHncP .

ameennihad commented 6 years ago

A side from analog input of the joystick, is it possible to run the same code on ESP8266?

chilipeppr commented 6 years ago

Yes, it would be, but I find that the cost of ESP32 is the same as ESP8266 now and the RAM limitations of ESP8266 vs ESP32 aren't worth the pain and suffering of ESP8266 anymore.

On Wed, May 23, 2018 at 8:16 AM ameennihad notifications@github.com wrote:

A side from analog input of the joystick, is it possible to run the same code on ESP8266?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chilipeppr/serial-port-json-server/issues/51#issuecomment-391385796, or mute the thread https://github.com/notifications/unsubscribe-auth/AHidbUmr2Z0qHAEMwfvQd9Rmhsk6EsqLks5t1X1IgaJpZM4UHncP .

ameennihad commented 6 years ago

I'm considering ESP8266 because I have number of unused boards, but no ESP32.

chilipeppr commented 6 years ago

I'd buy new boards. They're cheap

On Wed, May 23, 2018, 8:53 AM ameennihad notifications@github.com wrote:

I'm considering ESP8266 because I have number of unused boards, but no ESP32.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chilipeppr/serial-port-json-server/issues/51#issuecomment-391399264, or mute the thread https://github.com/notifications/unsubscribe-auth/AHidbVgeMfLboBjE8WitcPEsadA_b36Gks5t1YXjgaJpZM4UHncP .

ameennihad commented 6 years ago

I know, but shipping to Iraq takes 60 day.

ameennihad commented 6 years ago

ESP8266 is running out of memory, code might work with some optimization but I don't think it worth trying, I'll order ESP32, in the meantime I try to port your code using Python and use a usb game controller connected to RPI.

ameennihad commented 6 years ago

I ended up writing the code in c++, I have a functional code now, I can control the machine with a gamepad connected to Raspberry PI and do other stuff like zero-out the machine. I'm considering the following features:

I have a questions:

chilipeppr commented 6 years ago

Yes, there would be a way to do that. There is a "broadcast" command in SPJS that all connected websockets get copies of. So just send "broadcast start-job" or something like that and then write a macro that auto-loads in CP that watches for that broadcast command and sends the pubsub to play the Gcode. Look at the pubsub docs in the Gcode widget to see the docs on the pubsub command that plays the Gcode. It's something like chilipeppr.publish("/com-chilipeppr-gcode-widget/play", "");

On Mon, Jun 4, 2018 at 11:07 AM ameennihad notifications@github.com wrote:

I ended up writing the code in c++, I have a functional code now, I can control the machine with a gamepad connected to Raspberry PI and do other stuff like zero-out the machine. I'm considering the following features:

  • Memic the function of touch plate.
  • Connect E-Stop to RPi GPIO and send feedhold when the switch is pressed, I had issues connecting the switch directly to tinyg.

I have a questions:

  • Is it possible to tell SPJS to run the loaded gcode in CP? I guess no!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chilipeppr/serial-port-json-server/issues/51#issuecomment-394446730, or mute the thread https://github.com/notifications/unsubscribe-auth/AHidbbuu6OPYiyOQNhMybVuwtP1QSpy2ks5t5Xd8gaJpZM4UHncP .

chilipeppr commented 6 years ago

Try this macro. May have bugs. Not tested.

// This macro shows how to watch for the chilipeppr // broadcast command, respond to the broadcast payload // you're looking for, and then send an automatic play command // to send your Gcode to your machine var myWatchChiliPepprBroadcast = { init: function() { // Uninit previous runs to unsubscribe correctly, i.e. // so we don't subscribe 100's of times each time we modify // and run this macro if (window["myWatchChiliPepprBroadcast"]) { macro.status("This macro was run before. Cleaning up..."); window["myWatchChiliPepprBroadcast"].uninit(); } macro.status("Subscribing to broadcast pubsub event");

    // store macro in window object so we have it next time thru
    window["myWatchChiliPepprBroadcast"] = this;

    this.setupSubscribe();
},
uninit: function() {
    macro.status("Uninitting broadcast macro.");
    this.unsetupSubscribe();
},
setupSubscribe: function() {
    // Subscribe to both events because you will not
    // get onComplete if the controller is sophisticated
    // enough to send onExecute, i.e. TinyG will only
    // get onExecute events while Grbl will only get
    // onComplete events
    chilipeppr.subscribe("/com-chilipeppr-widget-serialport/onBroadcast",

this, this.onChiliPepprBroadcast); }, unsetupSubscribe: function() { chilipeppr.unsubscribe( "/com-chilipeppr-widget-serialport/onBroadcast", this.onChiliPepprBroadcast ); }, onChiliPepprBroadcast: function(data) { macro.status("Got onChiliPepprBroadcast."); console.log("got onChiliPepprBroadcast. data:", data); // See if it's our "start-job" command? if ("Cmd" in data && data.Cmd && data.Cmd == "Broadcast" && data.Msg == "start-job") { chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "Playing Gcode", "We got a broadcast command of start-job so playing Gcode.", 3000); setTimeout(this.playGcode, 1000); } }, playGcode: function() { macro.status("Playing gcode."); chilipeppr.publish("/com-chilipeppr-widget-gcode/play", ""); }, pauseGcode: function() { macro.status("Just paused gcode."); chilipeppr.publish("/com-chilipeppr-widget-gcode/pause", ""); } } myWatchChiliPepprBroadcast.init();

On Mon, Jun 4, 2018 at 11:45 AM John Lauer jlauer12@gmail.com wrote:

Yes, there would be a way to do that. There is a "broadcast" command in SPJS that all connected websockets get copies of. So just send "broadcast start-job" or something like that and then write a macro that auto-loads in CP that watches for that broadcast command and sends the pubsub to play the Gcode. Look at the pubsub docs in the Gcode widget to see the docs on the pubsub command that plays the Gcode. It's something like chilipeppr.publish("/com-chilipeppr-gcode-widget/play", "");

On Mon, Jun 4, 2018 at 11:07 AM ameennihad notifications@github.com wrote:

I ended up writing the code in c++, I have a functional code now, I can control the machine with a gamepad connected to Raspberry PI and do other stuff like zero-out the machine. I'm considering the following features:

  • Memic the function of touch plate.
  • Connect E-Stop to RPi GPIO and send feedhold when the switch is pressed, I had issues connecting the switch directly to tinyg.

I have a questions:

  • Is it possible to tell SPJS to run the loaded gcode in CP? I guess no!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chilipeppr/serial-port-json-server/issues/51#issuecomment-394446730, or mute the thread https://github.com/notifications/unsubscribe-auth/AHidbbuu6OPYiyOQNhMybVuwtP1QSpy2ks5t5Xd8gaJpZM4UHncP .

ameennihad commented 6 years ago

The "data" object passed to onChiliPepprBroadcast function is the message "start-job", there is no data.Cmd or data.Msg both are undefined! I just changed the if statement to following to make it work: if (data == "start-job") I'm sending the command this way: ws->send("broadcast start-job"); Am I missing something or this is a bug in your macro?

chilipeppr commented 6 years ago

Bug in my macro. I didn't test it. Your change sounds perfect.

On Mon, Jun 4, 2018 at 6:49 PM ameennihad notifications@github.com wrote:

The "data" object passed to onChiliPepprBroadcast function is the message "start-job", there is no data.Cmd or data.Msg both are undefined! I just changed the if statement to following to make it work: if (data == "start-job") I'm sending the command this way: ws->send("broadcast start-job"); Am I missing something or this is a bug in your macro?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chilipeppr/serial-port-json-server/issues/51#issuecomment-394554515, or mute the thread https://github.com/notifications/unsubscribe-auth/AHidbfVbUI2K9Sz7pAiGedFWSTbT0Xdbks5t5eOSgaJpZM4UHncP .

chilipeppr commented 6 years ago

BTW, have you looked at the C code you can download for the ShuttleXpress widget? It does pretty much what it sounds like you wrote as well.

On Mon, Jun 4, 2018 at 7:50 PM John Lauer jlauer12@gmail.com wrote:

Bug in my macro. I didn't test it. Your change sounds perfect.

On Mon, Jun 4, 2018 at 6:49 PM ameennihad notifications@github.com wrote:

The "data" object passed to onChiliPepprBroadcast function is the message "start-job", there is no data.Cmd or data.Msg both are undefined! I just changed the if statement to following to make it work: if (data == "start-job") I'm sending the command this way: ws->send("broadcast start-job"); Am I missing something or this is a bug in your macro?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/chilipeppr/serial-port-json-server/issues/51#issuecomment-394554515, or mute the thread https://github.com/notifications/unsubscribe-auth/AHidbfVbUI2K9Sz7pAiGedFWSTbT0Xdbks5t5eOSgaJpZM4UHncP .