Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protobuf send bug #49

Closed
willin opened this issue Jun 13, 2017 · 3 comments
Closed

protobuf send bug #49

willin opened this issue Jun 13, 2017 · 3 comments

Comments

@willin
Copy link
Contributor

willin commented Jun 13, 2017

Context

  • OS and version used: OS X 10.12.5
  • Node.js version: 8.1.0
  • npm version: 5.0.3
  • list of installed packages:
    • azure-iot-device-mqtt
    • azure-iot-device
    • @airx/proto

Description of the issue:

Sended: Protobuf Message Body (Buffer, 210bytes)
Received: (Buffer 304bytes)

Code sample exhibiting the issue:

msg.js

const { Message } = require('@airx/proto');
const timestamp = require('@airx/proto/timestamp');

const message = Message.create({
  did: 'device1',
  timestamp: timestamp.set(new Date() - 86400000),
  data: {
    gateway: {
      name: 'gateway'
    },
    attitude: {
      pitch: 1.23,
      poll: 1.234,
      yaw: 1.2345
    },
    battery: {
      percent: 84,
      charging: false,
      voltage: 123,
      current: 12345
    },
    dronestatus: {
      motors: true,
      flying: false
    },
    gnss: {
      satellite: 4,
      latitude: 131.12334,
      longitude: -131.1234,
      amsl: -111,
      ato: 123,
      timestamp: timestamp.set()
    },
    signal: {
      percent: 88,
      type: 4,
      protocal: 'tewssst',
      rssi: -111
    },
    custom: [{
      key: 'trest',
      val: {
        type_url: '123',
        value: new Buffer('asdfasdfasdfasd')
      }
    }, {
      key: 'tst2',
      val: {
        type_url: '123',
        value: new Buffer('asdfasdfasdfasd')
      }
    }
    ]
  }
});

const buffer = Message.encode(message).finish();
// console.log(Message.decode(buffer));
console.log(buffer.length, buffer.toString('hex'));
module.exports = buffer;

send.js

const clientFromConnectionString = require('azure-iot-device-mqtt').clientFromConnectionString;
const Message = require('azure-iot-device').Message;

const connectionString = 'xxx';

const client = clientFromConnectionString(connectionString);

function printResultFor(op) {
  return function printResult(err, res) {
    if (err) console.log(`${op} error: ${err.toString()}`);
    if (res) console.log(`${op} status: ${res.constructor.name}`);
  };
}

const connectCallback = function (err) {
  if (err) {
    console.log(`Could not connect: ${err}`);
  } else {
    console.log('Client connected');

    // Create a message and send it to the IoT Hub every second
    setInterval(() => {
      const message = new Message(require('./msg'));
      client.sendEvent(message, printResultFor('send'));
    }, 1000);
  }
};

client.open(connectCallback);

Console log of the issue:

210 '0a0764657669636531120a089e83f9c90510c88b1e1aba010a090a0767617465776179aa010a0da4709d3f1d19049e3fb2010908541000187b20b960ba010408011000c2013208
e4f26360c0210000000000c05bc0290000000000c05e40320a089ea6fec90510b0931eca0118085810041a07746577737373742091ffffffffffffffff019a061f0a057472657374121
466617364666173649a061a0a047473743212120a03313233120b6ac75f6ac75f6ac75f6ac7'

304 '0a0764657669636531120a08efbfbdefbfbdefbfbdefbfbd0510efbfbdefbfbd141aefbfbd010a090a0767617465776179efbfbd010a0defbfbd70efbfbd3f1d1904efbfbd3fefbfbd010908541000187b20efbfbd
60efbfbd010408011000efbfbd01320804113d49efbfbd66efbfbd6360401972efbfbdefbfbdefbfbdefbfbd6360efbfbd210000000000efbfbd5befbfbd290000000000efbfbd5e40320a08efbfbdefbfbdefbfbdefbfb
d0510efbfbdefbfbd14efbfbd0118085810041a077465777373737420efbfbdefbfbdefbfbdefbfbdefbfbdefbfbdefbfbdefbfbdefbfbd01efbfbd061f0a05747265737412160a03313233120f61736466617364666173
6466617364efbfbd061a0a047473743212120a03313233120b6aefbfbd5f6aefbfbd5f6aefbfbd5f6aefbfbd'

code caused:

https://github.com/Azure/azure-iot-sdk-node/blob/master/device/transport/mqtt/src/mqtt_base.ts#L189

remove toString() and tested ok.

willin added a commit to AirDwing/azure-iot-sdk-node that referenced this issue Jun 13, 2017
@pierreca
Copy link
Contributor

will follow up with this at the same time as #50

@pierreca
Copy link
Contributor

Fix was checked into master and will be a part of the next release.

@pierreca
Copy link
Contributor

pierreca commented Aug 5, 2017

@pierreca pierreca closed this as completed Aug 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants