123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter web
- name:pub.py
- author:rabin
- """
- from mqtt.pub import *
- import random
- import time
- def sensor():
- # 模拟设备数据
- gateway = '10086'
- def device():
- return str(random.randint(100000, 100010))
- def val():
- return str(random.randint(1, 50))
- hard = 'sensor'
- pubType = ('temperature', 'humidity')
- pub = Pub()
- while True:
- for v in pubType:
- key = hard+'/'+v+'/'+gateway+'/'+device()
- value = val()
- print 'key:' + key + ' value:' + value
- pub.push(key, value)
- time.sleep(1)
- def pic():
- gateway = '10086'
- pub = Pub()
- key = 'pic/'
- key = 'pic/pic_'
- gateway = '/' + gateway + '/100001'
- with open('admin/static/images/banner.png', 'rb') as f:
- data = f.readlines()
- total = len(data)
- key = key + str(total) + '_'
- i = 0
- print key
- for value in data:
- k = key + str(i) + gateway
- pub.push(k, value)
- print k
- i = i+1
- #with open('test.png', 'w') as f:
- #f.writelines(data)
- """
- handle = open('admin/static/images/banner.png', 'rb')
- img = handle.read(1)
- handle.close()
- data = struct.pack('c', img)
- print data
- """
- #pub.push(key, value)
- #sensor()
- pic()
|