Frontend Cloud event log not updating

I can see that my Beacon is working just fine when I am calling data from it via the api , but I can not see any updates in the event log in the IDE. I am trying to test a cloud code and I can’t see anything.
Is there a way to see if my code in the cloud code is working without the frontend of the IDE?

So you are sure that events are delivered to Cloud and you can query them using /v3/lte/device_events endpoint? And there is no data incoming at all in Cloud Event Log? Or you just don’t see your debug messages? Can you share your cloud code? Have you tried to refresh your browser and see if it fixes problem?

 print('start');
 const request = require('request-promise');
 module.exports = async function (event) {
 
 if (event.type === 'position-change') {
 print('inside');
 await request.post('https://satcar.dk/index.php?option=com_satcar&task=webservice.addbeacon', {json: true, body: event});}
 }
 
 print('finish');

Yes I /v3/lte/device_events endpoint gives me precise gps updates to the second. Unfortunately, I am not getting anything in the IDE cloud event log so I can not tell if my code is any good.

I copied your code to my app, pressed Deploy and it seems to work well - I can see start and finish and inside. It is hard to tell what might be wrong in your case.
Cloud Event Log is always shows events from all devices but for particular app release. So if you released your app using Release to production you should be seeing those events under particular release and not under draft or any other release. Make sure that you are observing events on the correct release. REST endpoint returns all events from all releases, unless parameters specify differently.


I am trying to see what responce I get back.
I get start but then few times per second I get :

Failed due to a compilation error:

ReferenceError: result is not defined

Hi Georgi! This is because you are using const which is block-scoped.

You declare the const result constant inside the if block, so it is not visible to the code outside. Here is your code, properly formatted, perhaps it will help you to see where each block begins and ends:

print('start');
const request = require('request-promise');
module.exports = async function(event) {

  if (event.type === 'position-change') {
    print('inside');
    const result = await request.post('https://satcar.dk/index.php?option=com_satcar&task=webservice.addbeacon', {
      json: true,
      body: event
    });
  }
  console.log(JSON.stringify(result));
}
print('finish');


I though const is active only within those {} .
Anyways I changed the code accordingly and I get the same thing.

Your code is now formatted better, but contains the same bug (: You are right, the const is only visible within the closest block { }.

Here is the correct way to fix your code:

module.exports = async function(event) {
  if (event.type === 'position-change') {
    print('inside');
    const result = await request.post('https://satcar.dk/index.php?option=com_satcar&task=webservice.addbeacon', {
      json: true,
      body: event
    });
    console.log(JSON.stringify(result)); // this will work because result is defined within the same block
  }
  // console.log(JSON.stringify(result)); // this causes error because here result is not defined within the exported function scope
}

Take a look at this tutorial, it describes the basics of using variables and constants in javascript https://dev.to/sandy8111112004/javascript-introduction-to-scope-function-scope-block-scope-d11

1 Like


great, not is haves only one error. It says


Thanks for the link I checked it out. Great now there is only one error. It says the request is not defined??
Does it mean that the javascript request is not running on my beacon?
I updated the software holding the top and side buttons multiple times till now.
I went to stacks overflow and looked for similar errors in others cases.
I tried:
const request = require(‘request’);
require(‘http’).request();
inside and outside the brackets but still the same error
Can you login to the ssd of f5ea3f85ed562fcde4e2110d14c5ff1f and check what is running on that beacon?
Can install libraries like that in there?

npm install --save request
npm install --save request-promise

“request is not defined”, because you’ve moved this line below your function, and commented it out:

const request = require('request-promise');

Re-add it at the top of your Cloud Code, and make sure it’s uncommented.


BTW, a friendly advice (: It seems like this might be the first time you’re writing JavaScript, in which case you might want to invest a few hours in some introductory, online JavaScript course/tutorial.

Long-term, it’ll save you much more time writing JavaScript code, including Estimote micro-app and Cloud code. And, JavaScript is generally a very good investment these days, it’s literally the most popular programming language out there (:

Codecademy, Udemy, and Coursera are some of the most popular online self-learning websites, and all of them have JavaScript courses, so you may want to start there.

Thanks I am trying to get some hours in learning javascript between my tickets.
The line is comented out because I copied the code that Janusz told me to use few lines up. I have tried multible times with and without this line without seccess I get the same error
error123

You wrongly put closing braces inside if block. Web editor highlights other brace when you put cursor near one.

1 Like

The braces are fine . We modified the code like this :

console.log(‘start’);
const request = require(‘request-promise’);
module.exports = async function exp(event) {

if (event.type === ‘position-change’) {
console.log(‘inside’);
const result = await request.post(‘https://satcar.dk/index.php?option=com_satcar&task=webservice.addbeacon’, {
json: true,
body: event
});
}
//console.log(JSON.stringify(result));
}
console.log(‘finish’);

module.exports = async function(event) must be module.exports = async function exp(event) to work.
I suggest you update your documentation .

module.exports = async function(event) must be module.exports = async function exp(event) to work.
I suggest you update your documentation .

It does throw a warning, I think it’s because our Web IDE doesn’t understand async functions too well at this point. However, despite the warning, it should work just fine. I agree this is confusing though, you’re not the first to bring this up (:

1 Like

Code you posted is different than code on screenshot and has console.log(JSON.stringify(result)); commented out. This line is still out of scope of result. If you bring commented line back you will still get result is not defined. I hope you already fixed it.
module.exports = async function(event) { ... } is a valid JavaScript definition of anonymous function and has nothing to do with problems you had before. See documentation. I tested your code with module.exports = async function exp(event) and with module.exports = async function(event) and they both work fine.

1 Like