Pepper: retrieving a memory variable in web app

631 Views Asked by At

I'm programming an app for the Aldebaran's Pepper robot. I'm using Choregraphe and I made a web app to display in robots tablet. I am trying to pass on a variable from Pepper's behavior to the web app javascript.

My idea was to insert a key, data pair in Pepper's memory with a default insertData box, and then to load the app and retrieve it from memory there. The javascript code would look something like this.

var session = new QiSession();
var memory;
session.service("ALMemory").then(function(m) {    
    memory = m;});
var data = memory.getData('key')

I think it is close to working, but it's not quite there yet. Any ideas?

What is in general the best way to pass a variable to javascript?

Kind regards,

(This question is similar to this one, but my approach is different and I was asked to create a new one.)

2

There are 2 best solutions below

0
On

Make sure everything is done as callbacks, as each NAOqi function gives you futures.

See doc here.

QiSession(function(session) {
    session.service("ALMemory").then(function(m) { 
        m.getData('key').then(function(data) {
            // do something with the data!
        }, console.log);
    },console.log);
},console.log);
0
On

Follow docs here.

1.Start a session.

2.Connect to ALMemory service

QiSession(function (session) {
      console.log("connected!");
      session.service("ALMemory").then(function (memory) {
        memory.subscriber("event-key").then(function(subscriber){
          subscriber.signal.connect(function(data){
            // use the data here
        });
        });
      }, function (error) {
        console.log("An error occurred:", error);
      });
    }, function () {
      console.log("disconnected");
    });