My First OctoPrint Plugin! It pulls in the data from the FilaWeigher, my filament weight/room temperature/humidity/pressure sensor

Here's a link to the FilaWeigher:

And here's a link to the plugin:

I'm not really sure how many of you have implemented the FilaWeigher in your setup, but if you have, please do me a favor and update it to the latest code, and then try out this plugin. Like I said, it's my first plugin, and I've literally only tested it on my main OP instance and a test one I spun in Ubuntu on WSL.

At this time, all this plugin does is grab the data from the FilaWeigher every x seconds, and displays the values on the sensors in OP, under the connection state.

Also, in my very biased opinion, it might be useful to look at this plugin if you are someone that is also writing their first plugin, and you aren't very strong with Python and JS. I tried to keep the code as slim as possible, and tried to put in a lot of comments.

Please let me know what you think.

  • It's probably a good idea to create/update your project's .gitignore file to include *.egg* and then git rm OctoPrint_Filaweigher.egg-info
  • I suppose this will work, I'm just not familiar with seeing it plugin_version = "2020.01.30.1"
  • I think I would check the IP address once in the init and store this under the main class as self.IPAddress (rather than looking it up every ten seconds)
  • Likewise, I would do something like this, too, in the init: self.isValid = self.is_valid_ipv4_address(IPAddress)... and then...
	def check_sensors(self):
		if self.isValid: #Check if it's a valid IP
			url = "http://" + self.IPAddress + "/json" #Create the URL string to use
			try: #Try connecting, and if it works, then send that data to the send_plugin_message

In this way, you've done a lookup (possibly from microSD) and a system call once at the beginning and then you're using that information for the duration of the print job. You'd have to test to see what happens if the filament sensor device goes offline during the print job, though.