External access to temperatures?

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

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

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

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']))

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:

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.

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

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

1 Like

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

@chillysmoks Grafana. Fairly fancy thing.

2 Likes

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

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.

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

Care to share this dashboard?

edited by mod
(one question mark is enough)

In a case like this I would want to coexist hotend temperature with its target into the same gauge.

1 Like

I am interested in my python program using the bed temperature and the code here looked just what I want. I quite simply copied the code given by tedder42 without any changes as I am not sure I fully understand it, dangerous I know!

The result was the error message below:
Traceback (most recent call last):
File "temp2.py", line 4, in
print("extruder temp: {}, target: {}".format(temperatures['tool0']['actual'], temperatures['tool0']['target']))
TypeError: 'NoneType' object is not subscriptable

Any help will be much appreciated, thank you.

Hello @allanoptical !

You noticed that this a quite old thread and that things may have changed in the software during that time?

grafik

You may open a new thread in Development - OctoPrint Community Forum

Thanks for your comments. I had noticed the age of the thread but my searches failed to anything else relevant apart from those mentioning writing a plug in. I fear the latter is beyond my limited skill with python.

The error is self-explanatory. You are trying to subscript an object which you think is a list or dict, but actually is None (i.e: the object has no value). This means that you tried to do:

None[something]

Here you attempted to index an object that doesn’t have that functionality. You might have noticed that the method sort() that only modify the list have no return value printed – they return the default None. This is a design principle for all mutable data structures in Python.

This ‘NoneType’ object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn’t define the getitem method.