Traceback (most recent call last):
File "./xbeetestmysql4.py", line 364, in OnTimer2
drawHum1(self,self.datacount,self.dataArray[0],SATUAN_HUM_UDARA,self.updatetimedb)
IndexError: list index out of range
the script
import wx
import os
from xbee import XBee,ZigBee
import time
import datetime
from time import strftime
import numpy as np
import matplotlib
matplotlib.use("WXAgg")
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
from matplotlib.ticker import MultipleLocator, FuncFormatter
import pylab
from matplotlib import pyplot
import MySQLdb
import MySQLdb as mdb
import sys, argparse, logging
import csv
import serial
import matplotlib.pyplot as plt
Assuming you are seeking help on running this in BlockPy, you should know that this code will never work - BlockPy (or rather, Skulpt) does not support WX, XBee, or MySql.
error
Traceback (most recent call last): File "./xbeetestmysql4.py", line 364, in OnTimer2 drawHum1(self,self.datacount,self.dataArray[0],SATUAN_HUM_UDARA,self.updatetimedb) IndexError: list index out of range
the script
import wx import os
from xbee import XBee,ZigBee import time import datetime from time import strftime import numpy as np import matplotlib matplotlib.use("WXAgg") from matplotlib.figure import Figure from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar from matplotlib.ticker import MultipleLocator, FuncFormatter import pylab from matplotlib import pyplot import MySQLdb import MySQLdb as mdb import sys, argparse, logging import csv import serial import matplotlib.pyplot as plt
ID_TIMER = 1 ID_TIMER2 = 2 ID_TIMER3 = 3 SATUAN_HUM_UDARA = '%RH' SATUAN_HUM_TANAH = '%RH' SATUAN_INT_CAHAYA = 'lx' db = MySQLdb.connect("localhost", "root", "raspberry", "sensor") cur = db.cursor() dbreadsensor=[] DBtime=0 currenttime=0
serial
arduino = serial.Serial('/dev/ttyUSB0',9600)
def readsensor():
data = arduino.read()
if(data=='A'):
data = arduino.readline()
pieces = data.split('#')
kelembapanUdara = pieces[0]
kelembapanTanah = pieces[1]
intensitasCahaya = pieces[3]
print pieces[0]
def saveDB(hum1,hum2,intCahaya): datetimeWrite=(time.strftime("%Y-%m-%d ")+time.strftime("%H:%M:%S")) dateupdate=datetimeWrite sql = (""" INSERT INTO datasensor VALUES (%s,%s,%s,%s)""",(datetimeWrite,kelembapanUdara,kelembapanTanah,intensitasCahaya)) try: cur.execute(*sql) db.commit() except: print 'Error'
def drawHum1(self,x,update,satuan,updatetime): self.arrxTEMP.append(x) self.arryTEMP.append(update) self.MPL1.cla()
self.MPL1.ylim(0,15)
def drawHum2(self,x,update,satuan,updatetime1): self.arrxHUM.append(x) self.arryHUM.append(update) self.MPL2.cla() self.MPL2.ylim(0,100) self.MPL2.plot(self.arrxHUM,self.arryHUM,':^b') self.MPL2.title_MPL("Hum Tanah") self.MPL2.ylabel(SATUAN_HUM_TANAH) self.MPL2.ShowUpdate(update,'%',updatetime1) self.MPL2.grid() self.MPL2.UpdatePlot()
def drawIntCahaya(self,x,update,satuan,updatetime2): self.arrxHUM.append(x) self.arryHUM.append(update) self.MPL2.cla() self.MPL2.ylim(0,100) self.MPL2.plot(self.arrxHUM,self.arryHUM,':^b') self.MPL2.title_MPL("Intensitas Cahaya") self.MPL2.ylabel(SATUAN_INT_CAHAYA) self.MPL2.ShowUpdate(update,'lx',updatetime2) self.MPL2.grid() self.MPL2.UpdatePlot()
class MatplotPanel(wx.Panel): def init(self,parent): wx.Panel.init(self,parent=parent, id=-1) font2 = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT) font2.SetPointSize(12) font3 = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT) font3.SetPointSize(25)
class WQMP2ET(wx.Frame):
if name == 'main':