1

I want to pass data from my choregraphe to webjs and the passed value will display it in the html through javascipt. I can successfully passed it but the problem is it will just display for a 1-3 seconds. Did i do this right?

Here is my code from choregraphe(python):

def onLoad(self):
    #put initialization code here
    pass

def onUnload(self):
    self.memory = None
    #put clean-up code here
    pass

def onInput_onStart(self):
    data = ['apple','mango','juice']
    self.memory.raiseEvent("myData", data)

def onInput_onStop(self):
    self.onUnload() 
box is stopped
    self.onStopped() 

And this is the code for my javaschipt in getting the data from pepper:

var  session = new QiSession();

$(document).ready(function(){
getData();
});
function getData(){
session.service('ALMemory').then(function(ALMemory){
  ALMemory.subscriber("myData").then(function(subscriber) {
    subscriber.signal.connect(function(data){
    "display to html here"
    });
    });
});
}

2 Answers2

1

Your Choregraphe code is full of bugs, and of useless boilerplate things you could just remove, this should be enough:

def onLoad(self):
    self.memory = self.session().service("ALMemory")

def onInput_onStart(self):
    data = ['apple','mango','juice']
    self.memory.raiseEvent("myData", data)

... as for the javascript side, there are two things to do:

  • As soon as the page loads, show the current value of the data - TVK's code does that
  • As soon as the value changes, update the page - your code does that.

Combined together, it would be something like this:

var session = new QiSession();
function updateDisplay(data) {
    "display to html here"
}
session.service('ALMemory').then(function(ALMemory){
  ALMemory.getData("myData").then(updateDisplay);
  ALMemory.subscriber("myData").then(function(subscriber) {
        subscriber.signal.connect(updateDisplay);
  });
});
Emile
  • 2,946
  • 2
  • 19
  • 22
0

Try to work with ALMemory.getData, rather than with ALMemory.subscriber. This might work for you:

var  session = new QiSession();

$(document).ready(function(){
getData();
});
function getData(){
session.service('ALMemory').then(function(ALMemory){
  ALMemory.getData("myData").then(function(data) {
    "display to html here"
    });
});
}
TVK
  • 1,042
  • 7
  • 21