Closed
Description
Hi guys,
I have almost everything ready to make the Cloud API possible:
- cloud discovery
- cloud aws login
- suscribe to topics in the cloud to receive state updates
- make changes in the state to set preferences ( schedule, bust, etc)
But i dont found the correct topic
and message
content to send basic commands like start
or stop
.
Anybody sniff that data? or has that data?
My sniff data is weired and malformed, i dont know if my sslsplit is showingme the info in the correct encoding. When I send a command with my phone over the cloud I see some bytes in the comunication but no one string like topic o json message.
can anybody help?
here is the working snippet:
const AWSIoTData = require('aws-iot-device-sdk');
const AWS = require('aws-sdk');
const request = require('request-promise');
// install with: npm install aws-iot-device-sdk aws-sdk request-promise request
const ROBOT_BLID = ''; // same as local api
const ROBOT_PASSWORD = ''; // same as local api
const APP_ID = ''; // like IOS-12345678-1234-1234-1234-123456789098
function cloudDiscovery () {
var requestOptions = {
'method': 'GET',
'uri': `https://disc-prod.iot.irobotapi.com/v1/robot/discover/${ROBOT_BLID}`,
'json': true
};
return request(requestOptions);
}
function cloudLogin () {
return cloudDiscovery().then(function (discoveryData) {
var postData = {
'associations': {
'0': {
'robot_id': ROBOT_BLID,
'deleted': false,
'password': ROBOT_PASSWORD
}
},
'app_id': APP_ID
};
var requestOptions = {
'method': 'POST',
'headers': {
'Content-Type': 'application/json',
'User-Agent': 'aspen/1.9.1.184.1 CFNetwork/808.2.16 Darwin/16.3.0'
},
'uri': `${discoveryData.httpBase}/v1/login`,
'body': postData,
'json': true
};
return request(requestOptions).then((rawLoginResponse) => {
return {login: rawLoginResponse.associations['0'], credentials: rawLoginResponse.credentials, discovery: discoveryData};
});
});
}
function initMQTT (amazonData) {
var awsConfiguration = {
poolId: amazonData.credentials.CognitoId,
region: amazonData.discovery.awsRegion
};
var AWSConfiguration = awsConfiguration;
var clientId = ROBOT_BLID + '-' + (Math.floor((Math.random() * 100000) + 1));
AWS.config.region = AWSConfiguration.region;
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: AWSConfiguration.poolId
});
const mqttClient = AWSIoTData.device({
region: AWS.config.region,
clientId: clientId,
protocol: 'wss',
maximumReconnectTimeMs: 8000,
debug: true,
accessKeyId: amazonData.credentials.AccessKeyId,
secretKey: amazonData.credentials.SecretKey,
sessionToken: amazonData.credentials.SessionToken
});
mqttClient.on('connect', function (e) {
console.log('connect!', e);
mqttClient.subscribe('$aws/things/' + ROBOT_BLID + '/shadow/#'); // all subtopics
// const cmd = {'state': {'desired': {'cleanSchedule': {'cycle': ['none', 'none', 'none', 'none', 'none', 'none', 'none'], 'h': [17, 10, 10, 12, 10, 13, 17], 'm': [0, 30, 30, 0, 30, 30, 0]}}}};
// mqttClient.publish('$aws/things/' + ROBOT_BLID + '/shadow/update', JSON.stringify(cmd));
});
mqttClient.on('reconnect', function () {
console.log('reconnect!');
});
mqttClient.on('message', function (t, m) {
console.log('message:');
console.log('topic:', t);
console.log(m.toString());
});
mqttClient.on('delta', function (m) {
console.log('delta:');
console.log(m);
});
mqttClient.on('status', function (m) {
console.log('status:');
console.log(m);
});
mqttClient.on('data', function (m) {
console.log('data:');
console.log(m);
});
mqttClient.on('error', function (e) {
console.log('error:');
console.log(e);
});
mqttClient.on('packetreceive', function (m) {
console.log('packetreceive:');
console.log(m);
});
}
cloudLogin().then((credentialData) => {
console.log(credentialData);
initMQTT(credentialData);
}).catch(console.log);