def test(): gearkey = "qnlgzsPUUxYeyQP" gearsecret = "1euJPvxybllEPQZzq2u9wpRJXDbjM7" appid = "testNo3" if(os.path.isfile("microgear.cache")): f = open((os.getcwd() + "/microgear.cache"), 'r') print(f.readlines()) f.close() else: print("yes1") client.create(gearkey, gearsecret, appid, {'debugmode': "True", 'scope': "chat:receiver"}) client.setname("sender") if(os.path.isfile("microgear.cache")): f = open((os.getcwd() + "/microgear.cache"), 'r') print(f.readlines()) f.close() else: print("yes2") client.connect() f = open((os.getcwd() + "/microgear.cache"), 'r') print(f.readlines()) f.close() client.resettoken() if(os.path.isfile("microgear.cache")): f = open((os.getcwd() + "/microgear.cache"), 'r') print(f.readlines()) f.close() else: print("yes3")
def testCreateNetPieLabel(): gearkey, gearsecret, appid = testCreateNetPie1(); client.create(gearkey, gearsecret, appid, {'label' : "Microgear Python"}) client.setname('logg') client.connect() print("Sleep for 90 seconds") time.sleep(90)
def testCreateNetPieScopeName(): gearkey, gearsecret, appid = testCreateNetPie1(); client.create(gearkey, gearsecret, appid, {'debugmode' : True, 'scope' : "name:logger"}) client.setname('logg') client.connect() print("Sleep for 90 seconds") time.sleep(90)
def start_connect(self): self.mySignal.emit('load') client.setname("remote") client.setalias("pyqt") client.on_connect = self.connection client.on_message = self.subscription client.on_disconnect = self.disconnect client.subscribe("/remote") client.connect()
def testCreateNetPieScopeChat(): gearkey, gearsecret, appid = testCreateNetPie1(); client.create(gearkey, gearsecret, appid, {'debugmode' : True, 'scope' : "chat:java ja"}) client.setname('Python ja') client.connect() def receive_message(topic, message): print topic + " " + message while(True): client.chat('Html ka', "Hello html") time.sleep(3) client.on_message = receive_message
def testScopeChat(): gearkey = "qnlgzsPUUxYeyQP" gearsecret = "1euJPvxybllEPQZzq2u9wpRJXDbjM7" appid = "testNo3" client.create(gearkey, gearsecret, appid, {'debugmode': "True", 'scope': "chat:receiver"}) client.setname("sender") client.connect() def receive_message(topic, message): print topic + " " + message while True: client.chat("not receiver","How are you?") time.sleep(3)
def testCreateNetPieScopeW(): gearkey = "ExhoyeQoTyJS5Ac" gearsecret = "gzDawaaHRe1KvQhepAw3WYuuGHjBsh" appid = "p107microgear" client.create(gearkey , gearsecret, appid, {'debugmode': True,'scope': "r:/LetsShare" }) client.create(gearkey , gearsecret, appid, {'debugmode': True,'scope': "w:/LetsShare" }) client.setname("Python ja") client.connect() def receive_message(topic, message): print topic + " " + message while True: client.publish("/StopsShare","Happy New Year!") time.sleep(3) client.on_message = receive_message
def testChat(): gearkey = "ExhoyeQoTyJS5Ac" gearsecret = "gzDawaaHRe1KvQhepAw3WYuuGHjBsh" appid = "p107microgear" origin = "oriA" destination = "destX" client.create(gearkey , gearsecret, appid, {'debugmode': True}) client.setname(origin) client.connect() def receive_message(topic, message): print topic + " " + message while True: client.chat(destination,"Hello world.") time.sleep(3)
def testResetToken(): gearkey = "ExhoyeQoTyJS5Ac" gearsecret = "gzDawaaHRe1KvQhepAw3WYuuGHjBsh" appid = "p107microgear" client.create(gearkey , gearsecret, appid, {'debugmode': True}) client.setname("Python ja") client.setname("Not Python ja") client.connect() def receive_message(topic, message): print topic + " " + message while True: time.sleep(3) print("hello") client.on_message = receive_message
def testChat(): gearkey = "ExhoyeQoTyJS5Ac" gearsecret = "gzDawaaHRe1KvQhepAw3WYuuGHjBsh" appid = "p107microgear" gear_name = "not receiver" client.create(gearkey , gearsecret, appid, {'debugmode': True}) client.setname(gear_name) client.connect() def receive_message(topic, message): print topic + " " + message while True: client.chat("not receiver", "hello") time.sleep(3) client.on_message = receive_message
left() elif message=="RIGHT": right() def right(): myMotor.run(Adafruit_MotorHAT.BACKWARD) for i in range(255): print "RIGHT"+str(i) myMotor.setSpeed(i) time.sleep(0.001) def left(): myMotor.run(Adafruit_MotorHAT.FORWARD) for i in range(255): print "LEFT"+str(i) myMotor.setSpeed(i) time.sleep(0.001) def stop(): mode = 0 turnOffMotors() client.setname("remote") client.setalias("raspberrypi") client.on_connect = connection client.on_message = subscription client.subscribe("/remote2") client.connect(True)
import microgear.client as client import time gearkey = "3Pz59oJzsIRox0g" gearsecret = "DqOZKONNM0Hk9HZOwqc1e96FTzRIHs" appid = "motatocity" client.create(gearkey,gearsecret,appid,{'debugmode': True}) def connection(): print ("Now, I am connected with netpie") def subscription(topic,message): print (topic+" "+message) def callback_message(topic, message) : print ("I got message from ", topic, ": ", message) client.setname("doraemon") client.on_connect = connection client.on_message = subscription client.on_message= callback_message client.subscribe("/chat") client.connect() while True: #client.chat("doraemon","Hello world. "+str(int(time.time()))) client.on_message= callback_message time.sleep(2)
def right(): myMotor.run(Adafruit_MotorHAT.BACKWARD) for i in range(255): print "RIGHT" + str(i) myMotor.setSpeed(i) time.sleep(0.001) def left(): myMotor.run(Adafruit_MotorHAT.FORWARD) for i in range(255): print "LEFT" + str(i) myMotor.setSpeed(i) time.sleep(0.001) def stop(): mode = 0 turnOffMotors() client.setname("remote") client.setalias("raspberrypi") client.on_connect = connection client.on_message = subscription client.subscribe("/remote2") client.connect(True)
ap.add_argument("-v", "--video", help="path to the video file") args = vars(ap.parse_args()) # How sizeLong have we been tracking # Initialize mutithreading the video stream. if args["video"] is None : camera = VideoStream(src=0, usePiCamera=True, resolution=frameSize, framerate=32).start() else : camera = cv2.VideoCapture(args["video"]) time.sleep(2.0) this_name = 'CAMERA' microgear.setname(this_name) microgear.on_reject = callback_reject microgear.on_connect = connection microgear.on_message = subscription microgear.on_error = callback_error microgear.connect(False) microgear.publish("/countPeople",countPeople) # Get the next frame. while True: # If using a webcam instead of the Pi Camera, if args["video"] is None : Frame = camera.read() # If using a video file else: _,Frame = camera.read() # cannot fetch Frame
# rospy.loginfo(hello_str) # pub.publish(hello_str) # rate.sleep() #//////////////////////Netpie/////////////////////////////////// appid = "HappyIoT Naja" gearkey = "HappyIoT Naja" gearsecret = "HappyIoT Naja" client.create(gearkey,gearsecret,appid,{'debugmode': True}) def connection(): print "Now I am connected with netpie" def subscription(topic,message): pub.publish(message) print topic+" "+message client.setname("doraemon") client.on_connect = connection client.on_message = subscription client.subscribe("/mails") client.connect(True) #////////////////////////////////////////////////////////////// #if __name__ == '__main__': # try: # talker() # except rospy.ROSInterruptException: # pass
def callback_error(msg) : #print(msg) def callback_reject(msg) : # print (msg) #print ("Script exited") exit(0) def encode_base64(img_data): encoded = None try: #compress it first. compressed_data = zlib.compress(img_data.getvalue(),9) #encode it to base64 string encoded = base64.b64encode(compressed_data) except: pass return encoded def decode_base64(compressed_b64str=None,save_to_file=None): try : #firstly, decode it decoded = base64.decodestring(compressed_b64str) decompr = zlib.decompress(decoded) #save it if is needed. if save_to_file is not None: with open(save_to_file,"wb") as fh: fh.write(decompr) else: #just display on screen w,h = 640,480 image = Image.open(BytesIO(decompr)) image.save('C:\\Users\\TO_MANG\\Documents\\testproject\\public\\test_snap.jpg') #image.show() except: pass this_name = 'n3a1' those_name = 'n3a2' this_role = 'receiver' running = True ready_to_receive = False netpie.setname(this_name) netpie.on_reject = callback_reject netpie.on_connect = connection netpie.on_message = subscription netpie.on_error = callback_error netpie.subscribe("/test") netpie.connect(False) if this_role == 'receiver' : while running: # print ("**** Search on receiver ****") time.sleep(2) pass #print ("End") else : running = False
key = 'application/key' secret = 'application/secret' app = 'application/name/appid' netpie.create(key, secret, app, {'debugmode': True}) def connection(): print "Now I am connected with netpie" def subscription(topic, message): print topic + " " + message netpie.setname("RPi") netpie.on_connect = connection netpie.on_message = subscription netpie.subscribe("/mails") netpie.connect() # random.randint(0,100) instead of temperature # random.randint(0,50) instead of Humidity while True: netpie.chat("RPi", str(random.randint(0, 100)) + "," + str(random.randint(0, 50))) time.sleep(2)
str_img.seek(0) return str_img camera = PiCamera() camera.resolution=(640,480) this_name = 'n3a2' those_name = 'n3a1' this_role = 'sender' running = True ready_to_send = False netpie.setname(this_name) netpie.on_reject = callback_reject netpie.on_connect = connection netpie.on_message = subscription netpie.on_error = callback_error netpie.subscribe("/test") netpie.connect(False) if this_role=='sender': while not ready_to_send : netpie.chat(those_name,'ruok') time.sleep(2) snap_shot = snap()
class StartWindows(QMainWindow): def __init__(self, camera=None, parent=None): super(StartWindows, self).__init__(parent=parent) self.ui = Ui_Form() self.ui.setupUi(self) self.detections = None self.frame = None self.files = [] self.tmp = [] self.start = 0 self.update_timer = QTimer() self.update_timer.timeout.connect(self.update) #User self.Qr_User = "" self.Point = 0 #button self.ui.pushButton_2.clicked.connect(self.yolo_tiny) self.ui.pushButton.clicked.connect(self.stop) #camera self.camera = cv2.VideoCapture(0) self.update_timer.start(30) #qr self.qr = cv2.QRCodeDetector() ''' def update2(self): self.update_timer2.start(30) ret,self.frame =self.camera.read() self.frame=cv2.flip(self.frame,1) cv2.imshow("img", img) ''' def connection(): print("Now I am connected with netpie") def subscription(topic, message): logging.info(topic + " " + message) def disconnect(): logging.debug("disconnect is work") appid = "ProjectOs" gearkey = "B0r3CNqaRtDjDf0" gearsecret = "qRjL4WFFGCZqXY6hkpHFKkLIx" client.create(gearkey, gearsecret, appid, {'debugmode': True}) client.setname("doraemon") client.on_connect = connection client.on_message = subscription client.subscribe("/mails") client.connect() def yolo_tiny(self): self.start = 1 self.execution_path = os.getcwd() self.detector = ObjectDetection() self.detector.setModelTypeAsTinyYOLOv3() self.detector.setModelPath( os.path.join(self.execution_path, "yolo-tiny.h5")) self.detector.loadModel(detection_speed="flash") print("###you are use yolo_tiny model###") def update(self): if (self.start == 0): print("QR") ret, self.frame = self.camera.read() decodedObjects = pyzbar.decode(self.frame) for obj in decodedObjects: if obj.data: self.Qr_User = str(obj.data) self.Qr_User = self.Qr_User[2:len(self.Qr_User) - 1] print(self.Qr_User) self.frame = cv2.flip(self.frame, 1) self.frame = cv2.resize(self.frame, (891, 501)) height, width, channel = self.frame.shape bytesPerLine = 3 * width qImg = QImage(self.frame.data, width, height, bytesPerLine, QImage.Format_RGB888).rgbSwapped() pixmap01 = QPixmap.fromImage(qImg) pixmap_image = QPixmap(pixmap01) self.ui.label.setPixmap(pixmap_image) self.ui.user_id.setText(self.Qr_User) self.ui.label.show() if (self.start == 1): ret, self.frame = self.camera.read() self.frame = cv2.flip(self.frame, 1) #detected custom_objects = self.detector.CustomObjects(bottle=True) detected_image_array, self.detections = self.detector.detectCustomObjectsFromImage( custom_objects=custom_objects, input_type="array", input_image=self.frame, output_type="array") for eachObject in self.detections: print(eachObject["name"], " : ", (eachObject["percentage_probability"]), " : ", eachObject["box_points"]) if int(eachObject["percentage_probability"]) >= 50: self.Point += 1 time.sleep(0.5) print(self.Point) #resize detected_image_array = cv2.resize(detected_image_array, (891, 501)) height, width, channel = detected_image_array.shape bytesPerLine = 3 * width qImg = QImage(detected_image_array.data, width, height, bytesPerLine, QImage.Format_RGB888).rgbSwapped() pixmap01 = QPixmap.fromImage(qImg) pixmap_image = QPixmap(pixmap01) self.ui.label.setPixmap(pixmap_image) self.ui.user_id.setText(self.Qr_User) self.ui.user_point.setText(str(self.Point)) self.ui.label.show() ''' def score(): d=self.detections for eachObject in d: if int(eachObject["percentage_probability"]) >=50 : self.Point+=1 print(self.Point) ''' def stop(self): #ส่งข้อมูลช่วงนี้ก่อนแล้วเคลียค่า print(self.Qr_User) print(self.Point) client.publish("/Point2", str(self.Point)) client.publish("/Name", str(self.Qr_User)) client.publish("/Mix", (str(self.Qr_User) + "," + str(self.Point))) self.start = 0 self.Qr_User = "" self.Point = 0 self.ui.user_point.setText(str(self.Point)) print(self.Qr_User) print(self.Point) def start(self): self.update_timer.start(30)