External access to temperatures?


#1

I am working on a way to graph the temperatures in Graphite/Grafana, currently the only way I have discovered to do this is through the serial log however that causes system load or i/o issues.

Is there a place to hook in a simple python script for example

    sock.connect((CARBON_SERVER, CARBON_PORT))
    sock.sendall(message)
    sock.close()

Where $message = "3dprinter.ultimate.HotEnd.realtemp $tool/bed $stamp"
Would like to have target temperature as well as actual temperature.

In the current model I have also defined max temperatures that are gathered from 1-wire sensors mounted close to the print head and the hot bed as well as the ambient air in the enclosure.

PI system loads never go over .4 but the print buffer to the printer empties and the printer pauses causing small blobs in the model that is printing......

Any suggestions would be appreciated.

Thank you


#2

Write a plugin that implements this hook and have it send the collected temperature data to your external backend.


#3

Thank you. Not sure I'm up for the task, I'm really new to python.


#4

You might find calling the REST API every few seconds/minutes an easier alternative.

import requests
tret = requests.get('http://octopi.local/api/printer', headers={'X-Api-Key': 'abcdef...'})
temperatures = tret.json().get('temperature')
print("extruder temp: {}, target: {}".format(temperatures['tool0']['actual'], temperatures['tool0']['target']))

#5

That is just too simple in comparison to parsing the serial log. I can now combine the 1-wire and the actual/target readings into 1 python script.

Thank you very much :grinning:


#6

Another question, how can I tell if octoprint is connected to the printer? If I try to read the API while not connected the script I have is failing otherwise it is working quite well.


#7

This seems to work for a check if connected.
if requests.get(req_addr, headers={'X-Api-Key': api_key}):
...


#8

Here is what the output from the temperature monitoring looks like during an active print.


#9

What is that?????????


#10

@chillysmoks Grafana. Fairly fancy thing.


#11

I like it! That's a reason I love open source projects!


#12

Statistics really...... Simply graphs of the temperatures gathered during a print. One of my printers has the safety features of the firmware disabled and there is no OEM update available, cooking up another version of firmware would be a long process to have the same printer so I have not approached that yet. This version of the script/hack has built in temperature maximums hooked to both the firmware gathered temps and to the 1-wire temps and the ability to shut off the AC power using a DLI Web Power Switch if temps go out of spec. Just about any smart plug could be used I am sure since all it does is call an external shell script it would customize easily.

Very Pre-Beta in nature and not a great solution to the firmware lacking safety but it provided the incentive to learn how to collect the data and set some alarms/actions at least.


#13

I went through the plugin tutorial I am going to give making the plugin a shot. I will need to learn to use the OctoPrint methods instead of using the API. I am curious if there is a list of Python modules that are included in the virtual/chroot environment? To run stand alone I had to install some modules and just installed the libraries at the OS level with apt-get.

Modules used;
import os
import signal
import sys
import time
import socket
import syslog
import smtplib
import subprocess
import requests
import stat
import os.path