Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. let MIC = require('mic-sdk-js').default
  2.  
  3. const CONFIG = {
  4. // Username of the Cognito user
  5. username: 'thomasbn94',
  6.  
  7. // Password of the Cognito user
  8. password: 'Kake1234',
  9.  
  10. // The application endpoint
  11. app: 'startiot.mic.telenorconnexion.com',
  12.  
  13. // Elasticsearch query
  14. query: {
  15. size: 100,
  16. query: {
  17. bool: {
  18. filter: {
  19. bool: {
  20. minimum_should_match: 1,
  21. must: [{
  22. terms: {
  23. thingName: ['00001319']
  24. }
  25. },
  26. {
  27. range: {
  28. timestamp: {
  29. gte: + new Date() - (60 * 60 * 24 * 40), // 1 = days
  30. lte: + new Date()
  31. }
  32. }
  33. }],
  34. should: [{
  35. exists: {
  36. field: 'state.payload'
  37. }
  38. }]
  39. }
  40. },
  41. sort: {
  42. timestamp: {
  43. order: 'desc'
  44. }
  45. },
  46. _source: ['state.payload', 'timestamp']
  47. }
  48. }
  49. }
  50. }
  51.  
  52. // Instantiate a new Managed IoT Cloud API object
  53. let api = new MIC
  54.  
  55. // Init by providing the app endpoint
  56. var foo = function(params) {
  57. // The manifest is fetched and a 'unauthorized'
  58. // Cognito identity is created
  59. return api.init(CONFIG.app).then((manifest, credentials) => {
  60.  
  61. // Login the Cognito user
  62. return api.login(CONFIG.username, CONFIG.password).then(user => {
  63.  
  64. // Invoke ObservationLambda FIND with a query payload
  65. return api.invoke('ObservationLambda', { action: 'FIND', query: CONFIG.query }).then(res => {
  66. console.log("params = ", params)
  67. return JSON.stringify(res);
  68. })
  69. })
  70. }).catch(err => console.error(err));
  71. }
  72.  
  73.  
  74.  
  75. module.exports = {
  76. getData: function () {
  77. return foo();
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement