コード例 #1
0
 def set_display_1(self, x, y, cpum, memm, ipadd, netm):
     self.x = x
     self.y = y
     self.cpum = "Cpu(s):%s Up:%s" \
      % (str(cpum[0])+'%', str(cpum[1]).split('.')[0])
     self.memm = "Mem: %s %.0f%% %s free" \
      % (BasicDef.bytes2human(memm[0]), memm[1], BasicDef.bytes2human(memm[2]))
     self.ipadd = "Wlan0: " + ipadd
     self.netm = "Tx %s,  Rx %s" % \
       (BasicDef.bytes2human(netm[0]), BasicDef.bytes2human(netm[1]))
コード例 #2
0
    def __init__(self):
        # 设备ID
        self.DEVICEID = BasicDef.get_device_id()
        # APIKEY
        self.APIKEY = BasicDef.get_apikey()

        self.num = 0
        self.dict = {"datastreams": []}
        self.SENSORID = []
        self.payload = {}
コード例 #3
0
 def run(self):
     while self.__running.isSet():
         time.sleep(self.cputimesleep)
         self.cpum = self.cpu_usage()
         if self.post2OneNet:
             self.onenet.num += 1
             if self.onenet.num >= 10:
                 if BasicDef.get_network_status():
                     self.onenet.set_post_data_flow("CPU", self.cpum[0])
                     r = self.onenet.post_data_flow()
                 self.onenet.num = 0
コード例 #4
0
def main(argv):
    m = argv[1:]
    #检查是否有参数传入
    if m == []:
        print("Parameters Not exsit! You can't use OneNet API")
    #检查配置文件是否存在
    elif (os.path.isfile(argv[1]) == False):
        print("file: " + argv[1] + " not exist! You can't use OneNet API")
    else:
        #捕获异常,检查是否对应配置文件中的参数
        try:
            _deviceid = BasicDef.get_pares_info(argv, 'deviceid')
            # print('_deviceid: ', _deviceid)
            _apikey = BasicDef.get_pares_info(argv, 'apikey')
            # print('_apikey: ', _apikey)
        except KeyError as e:
            print("--device=%s is not exsit!" % e)
            return

        #检查没有问题,将配置文件中的_deviceid,_apikey 设置为全局可获取
        BasicDef.set_device_id(_deviceid)
        BasicDef.set_apikey(_apikey)
        #初始化onenet对象
        rPi = OneNetApi()

        #上传10个数据点到数据流Test1/Test2
        # test_repost(rPi, 'Test1')

        #读取最新上传数据流的数据点
        # test_get_dataflow(rPi, 'Test1')

        #读取某个数据流中最近的10个数据点
        test_get_datapoints(rPi, 'Test1', 10)
コード例 #5
0
	def run(self):
		while self.__running.isSet():
			time.sleep(self.timesleep)
			is_T_H = self.getTH()
			if is_T_H != False:
				self.T_H = is_T_H
				if self.post2OneNet:
					self.onenet.num += 1
					if self.onenet.num >= 1:
						if BasicDef.get_network_status():
							self.onenet.set_post_data_flow("T", self.T_H[0])
							self.onenet.set_post_data_flow("H", self.T_H[1])
							r = self.onenet.post_data_flow()
						self.onenet.num = 0
コード例 #6
0
    def run(self):
        self.is_device = self.connect_s80053()
        while self.__running.isSet():
            time.sleep(self.timesleep)
            if self.is_device:
                self.co2 = self.read_CO2()

            if self.post2OneNet:
                self.onenet.num += 1
                if self.onenet.num >= 5:
                    if BasicDef.get_network_status():
                        self.onenet.set_post_data_flow("co2", self.co2)
                        r = self.onenet.post_data_flow()
                    self.onenet.num = 0
コード例 #7
0
    def run(self):
        #初始化pm传感器失败时
        try:
            self.open_pm_port()
        except OSError as e:
            self.is_device = False
            print("Unable to connect to %s", self.device)
            return self.is_device
        while self.__running.isSet():
            time.sleep(self.timesleep)
            self.pm_res = self.get_pm_data()
            if self.pm_res == False:
                continue

            self.timestamp = self.pm_res['timestamp']
            self.apm10 = self.pm_res['apm10']
            self.apm25 = self.pm_res['apm25']
            self.apm100 = self.pm_res['apm100']
            self.pm25 = self.pm_res['pm25']
            self.pm10 = self.pm_res['pm10']
            self.pm100 = self.pm_res['pm100']
            self.gt03um = self.pm_res['gt03um']
            self.gt05um = self.pm_res['gt05um']
            self.gt10um = self.pm_res['gt10um']
            self.gt25um = self.pm_res['gt25um']
            self.gt50um = self.pm_res['gt50um']
            self.gt100um = self.pm_res['gt100um']
            self.all_PMS = [
                self.apm10, self.apm25, self.apm100, self.pm10, self.pm25,
                self.pm100, self.gt03um, self.gt05um, self.gt10um, self.gt25um,
                self.gt50um, self.gt100um
            ]

            if self.post2OneNet:
                self.onenet.num += 1
                if self.onenet.num >= 10:
                    if BasicDef.get_network_status():
                        self.onenet.set_post_data_flow("apm10", self.apm10)
                        self.onenet.set_post_data_flow("apm25", self.apm25)
                        self.onenet.set_post_data_flow("pm10", self.pm10)
                        self.onenet.set_post_data_flow("pm25", self.pm25)
                        # self.onenet.set_post_data_flow("gt03um", self.gt03um)
                        # self.onenet.set_post_data_flow("gt05um", self.gt05um)
                        r = self.onenet.post_data_flow()
                    self.onenet.num = 0