본문 바로가기

3D Printer/OctoPrint

OctoPrint Plugin 만들기 #9 (온도 그래프 Update시 send_plugin_message 이용하기)

OctoPrint Plugin 만들기 #9 (온도 그래프 Update시 send_plugin_message 이용하기)



옥토 프린트 플러그인 만들기 (챔버 매니저)



□ 필요 함수


 - Back End  : send_plugin_message

 - Front End : onDataUpdaterPluginMessage



[ Back End ]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    def checkTemperature(self):
        try:
            if self.device.is_open == True :
                # Serial data send
                msg = 'CMD O'+self.ControlObjectToID['TempCurrent']+' R0\n'
                self.device.writelines(msg.encode('ascii','ignore'));
                ret = self.device.read_until('\r');
                if ret.startswith('OK')==True :
                    tok = ret.split(' ')
                    self.tempCurrent = float(tok[2])
                    if len(self.tempAmbient) < 900 :
                        self.tempAmbient.append(self.tempCurrent)
                        self.tempTarget.append(self.tempControlTarget)
                        self.tempLabel.append(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                    else :
                        for i in range(0899) :
                            self.tempAmbient[i] = self.tempAmbient[i+1]
                            self.tempTarget[i] = self.tempTarget[i+1]
                            self.tempLabel[i] = self.tempLabel[i+1]
                        self.tempAmbient[899= self.tempCurrent
                        self.tempTarget[899= self.tempControlTarget
                        self.tempLabel[899= datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                
                TempData = {
                    'Actual'   : self.tempCurrent,
                    'Target'    : self.tempControlTarget,
                    'TimeStamp' : datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                }
                self._plugin_manager.send_plugin_message(self._identifier, dict(current_temp=TempData))
cs




[ Front End ]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
        self.onDataUpdaterPluginMessage = function (plugin, data) {
            if (typeof plugin == 'undefined'){
                return;
            }
            if (plugin != "chambermanager") {
               return;
            }
 
            if (data.hasOwnProperty("current_temp")) {
                if(self.historyTempChecked==false) {
                    self.historyTempChecked = true;
                    self.getCurrentTemp('HISTORY');
                }
                self.processCurrentTemp(data.current_temp.Actual, data.current_temp.Target, data.current_temp.TimeStamp);
            }
        };
 
cs