Get Hotend Temperature from websocket


My ideas is to read the actual Hotend temperature with websocket with a bash script running in cron every x time using "curl" command.

This script manage the fan power (dedicated GPIO) according the temperature.

Now have the fan always on also when the temperature is about 20°C

Can help me with Websocket usage?


  • Curl and websocket is not going to work, but that is also not necessary. For just fetching the temperatures you can use the request to websocket command bridge as described here:

    User websocket commands directly

    In the websocket chapter you will see all the small commands you normally use while you are displaying server status. Soem of them might also be useful for simple apps just wanting to show some informations. For these we offer a access over the REST api. The only thing that does not work are events as they are reported to open sockets only.

    http://localhost:3344/printer/api/<slug>?a=<websocket command>&data=<json object properly url-escaped>&apikey=<API key>>

    The above schema can be used to send any websocket command as REST call. Use GET or POST just as you like. For bigger data POSt should be preferred. You can replace apikey with sess, but you would normally do this only if you have no session open, so apikey is the normal way to use it.

    Then use


    Parameter: includeHistory (bool) include complete temperature history.


    { "irapid": { "activeExtruder": 0, "debugLevel": 6, "extruder": [ { "history": [ { "O": 0, "S": 0, "T": 25.5, "t": 1420570143740 }, { "O": 0, "S": 0, "T": 25.39999961853027, "t": 1420570144751 }, { "O": 0, "S": 0, "T": 25.39999961853027, "t": 1420570145759 }
            ], "output": 0, "tempRead": 25.5, "tempSet": 0 }, { "history": [ { "O": 0, "S": 0, "T": 25.5, "t": 1420570143740 }, { "O": 0, "S": 0, "T": 25.39999961853027, "t": 1420570144751 }, { "O": 0, "S": 0, "T": 25.5, "t": 1420570145759 }
            ], "output": 0, "tempRead": 25.5, "tempSet": 0 } ], "fanOn": false, "fanVoltage": 0, "firmware": "Repetier_0.92", "firmwareURL": "", "flowMultiply": 100, "hasXHome": false, "hasYHome": false, "hasZHome": false, "heatedBed": { "history": [], "output": 0, "tempRead": 0, "tempSet": 0 }, "layer": 0, "numExtruder": 2, "powerOn": false, "sdcardMounted": true, "speedMultiply": 100, "x": -21, "y": 0, "z": 0 } }

    Polls the detailed printer state with or without a complete temperature history.

    with includeHistory false to get you json response.

  • First time i execute 


    to get the api key.

    after i put this line in web browser:

    http://printer_address:3344/printer/api/<slug>a=<websocket command>&data=<json object properly url-escaped>&apikey=<14e7bf36-7537-46ad-a92b-08c43c81e82a>>

    but always get 

    {"error":"Authorization required"}
    Can help me?
    Thanks in advance.
  • Don't rely on info to get apikey. It is only there if server is configured to be accessible without protection, otherwise it is hidden.
    Parts in <> are placeholders and you need to replace them with the content.


    replace irapid with your printer.

    To encode/decode the data part you can use this:

  • Hi,

    many thanks.

    Based on your indication, i've done my things and all work very well.

    I want to share with you my project so if you do a thought you can implement directly in new version.

    I'done this on raspberry pi 2:

    Installed  fbi with sudo apt-get install fbi

    Have create a script called and and an image file estop.jpg.
    #! /bin/sh
    #   (->|-) = Diodo 1N4007 o 1N4148
    #   (NC E-STOP) = Contatto NC pulsante di emergenza
    #   GPIO4-----(->|-)------ CHx FAN
    #   GPIO27----(->|-)------ CHx FAN
    #   3V3-----------(NC E-STOP)-------GPIO17

    TARGET=30 #Temperatura di innesco della FAN

    sudo echo "4" > /sys/class/gpio/export #GPIO4 FAN OR-1
    sudo echo "17" > /sys/class/gpio/export #GPIO17 INPUT E-STOP
    sudo echo "27" > /sys/class/gpio/export #GPIO27 FAN OR-2
    sudo echo "out" > /sys/class/gpio/gpio4/direction
    sudo echo "in" > /sys/class/gpio/gpio17/direction
    sudo echo "out" > /sys/class/gpio/gpio27/direction
    sudo echo "0" > /sys/class/gpio/gpio27/value 

    while :
       STATUS=$(cat /sys/class/gpio/gpio17/value)
       if [ $STATUS = "0" ]; then
         # ESTOP PRESSED
         sudo wget -O /tmp/estop.log "http://localhost:3344/printer/api/"$NAME"?a=emergencyStop&apikey="$KEY""
         sleep 1
    sudo rm -r /tmp/estop.log
         sudo wget -O /tmp/estop.log "http://localhost:3344/printer/api/"$NAME"?a=deactivate&apikey="$KEY"&data=%7B%22printer%22%3A%22"$SLUG"%22%7D"
         sleep 1
    sudo rm -r /tmp/estop.log
         sudo echo "1" > /sys/class/gpio/gpio27/value
    sudo fbi -T 1 /home/pi/Desktop/estop.jpg
          while :
             STATUS=$(cat /sys/class/gpio/gpio17/value)
             if [ $STATUS = "1" ]; then
       sleep 2
       sudo pkill -f fbi
       sleep 2
       sudo fbi -T 1 /home/pi/Desktop/estop.jpg
          sudo wget -O /tmp/estop.log "http://localhost:3344/printer/api/"$NAME"?a=activate&apikey="$KEY"&data=%7B%22printer%22%3A%22"$SLUG"%22%7D"
          sudo echo "0" > /sys/class/gpio/gpio27/value
      sudo pkill -f fbi
          sudo wget -O /tmp/temp.log "http://localhost:3344/printer/api/"$NAME"?a=stateList&apikey="$KEY"&data=%7BincludeHistory%3Afalse%7D"
      TEMP=$(cat /tmp/temp.log | jq '.Test.extruder[0].tempRead')
      VAL=$(printf '%d\n' "$TEMP")
      if test $VAL -ge $TARGET
            sudo echo "1" > /sys/class/gpio/gpio4/value
            sudo echo "0" > /sys/class/gpio/gpio4/value
      sudo rm -r /tmp/temp.log
      sleep 1
    #! /bin/sh
    sudo nohup /home/pi/Desktop/ &
    sleep 5

    and put all in /home/pi/Desktop directory

    after have moved  into /etc/init.d directory

    have assigned -x permission to all script
    end have registered to start at boot with:

    sudo update-rc.d defaults

    and finally reboot system

    Now the fan to cool the hothend is directly controlled by GPIO4 according the temperature.

    If i press emergency button, script send a reset, and deactivate printer , activate hothend fan and blink every 2 seconds the image on display.

    If i restore the emergency button the image stop blink and the printer is reactivated.

  • attached all files:
  • i've done a video but cannot sent it
  • That is very special, so i would not integrate it as default.

    The server has a module system, so you could write more or less the same as a server module. That way you need to query of the server and can get data directly in the server as the script has access to important parts. We also have a emergency function in server.
Sign In or Register to comment.