示例#1
0
    def get_drone_data(self):
        payload = CayenneLPP()
        gps = self.vehicle.location.global_relative_frame
        imu = self.vehicle.raw_imu
        ned = self.vehicle.location.local_frame
        attitude = self.vehicle.attitude

        payload.addGPS(1, gps.lat, gps.lon, gps.alt)
        payload.addGyrometer(3, imu.xgyro, imu.ygyro, imu.zgyro)
        payload.addAccelerometer(5, imu.xacc, imu.yacc, imu.zacc)
        payload.addNED(7, ned.north, ned.east, ned.down)
        payload.addAttitude(9, attitude.pitch, attitude.yaw, attitude.roll)

        print("------------")
        print(gps)
        print(ned)
        print(imu)
        print(attitude)
        print("------------")

        cayenne_format_payload = binascii.hexlify(
            payload.getBuffer()).decode('utf8')
        print(cayenne_format_payload)
        return cayenne_format_payload
示例#2
0
    pm25, pm10 = run_sds011.run_sensor()
    print('Air Quality PM2.5: {}, PM10: {}'.format(pm25, pm10))
    # make the socket blocking
    # (waits for the data to be sent and for the 2 receive windows to expire)
    s.setblocking(True)

    # send some data
    c = CayenneLPP()
    c.addAnalogOutput(2, acc.pitch())
    c.addAnalogOutput(25, pm25)
    c.addAnalogOutput(10, pm10)
    # Check if GPS data was found
    if coords[0] is not None:
        coords = gps.coordinates()
        if coords[0] is not None and coords[1] is not None:
            c.addGPS(5, coords[0], coords[1], 0)
    s.send(bytes(c.getBuffer()))
    print('SENT')

    # make the socket non-blocking
    # (because if there's no data received it will block forever...)
    s.setblocking(False)
    # every 10 seconds i want it to blink
    # get any data received (if any...)
    data = s.recv(64)
    print(data)

    print(coords)
    now = utime.time()
    print('It has been {} seconds since last GPS check.'.format(now -
                                                                check_gps))