Search code examples
pepper

Load Url on Pepper's Tablet


I'm trying to load a website on Pepper like "www.google.com"

I'm sure we are connected on the same network. I've tried doing "http://www.google.com" too on the ShowApp Dialog.

I've seen this guide: http://kokorobot.com/2016/08/08/how-to-use-pepper-tablet

class MyClass(GeneratedClass):

    def __init__(self):
        GeneratedClass.__init__(self)

    def onLoad(self):
        self.isRunning = False

    def onUnload(self):
        self.isRunning = False

    def _getTabletService(self):
        tabletService = None
        try:
            tabletService = self.session().service("ALTabletService")
        except Exception as e:
            self.logger.error(e)
        return tabletService

    def onInput_onStart(self):
        if self.isRunning:
            return # already running, nothing to do
        self.isRunning = True
        # We create TabletService here in order to avoid
        # problems with connections and disconnections of the tablet during the life of the application
        tabletService = self._getTabletService()
        appName = self.packageUid()
        state = False
        if appName:
            if tabletService:
                if tabletService.loadApplication(appName):
                    tabletService.loadUrl("www.google.com")                    self.logger.info("Successfully set application: %s" % appName)
                    tabletService.showWebview()
                    state = True
                else:
                    self.logger.warning("Got tablet service, but failed to set application: %s" % appName)
            else:
                self.logger.warning("Couldn't find tablet service, so can't set application: %s" % appName)
        if state:
            self.onSuccess()
        else:
            self.onFailure()

Solution

  • If you want to show a web consider using the box "Show Web View" instead. I've found that Show App gives more trouble than it's worth it.

    class MyClass(GeneratedClass):
    
        def __init__(self):
            GeneratedClass.__init__(self)
    
        def onLoad(self):
            pass
    
        def onUnload(self):
            pass
    
        def _getTabletService(self):
            tabletService = None
            try:
                tabletService = self.session().service("ALTabletService")
            except Exception as e:
                self.logger.error(e)
            return tabletService
    
        def _getAbsoluteUrl(self, partial_url):
            import os
            subPath = os.path.join(self.packageUid(), os.path.normpath(partial_url).lstrip("\\/"))
            # We create TabletService here in order to avoid
            # problems with connections and disconnections of the tablet during the life of the application
            return "http://%s/apps/%s" %(self._getTabletService().robotIp(), subPath.replace(os.path.sep, "/"))
    
        def onInput_onStart(self):
             # We create TabletService here in order to avoid
            # problems with connections and disconnections of the tablet during the life of the application
            tabletService = self._getTabletService()
            if tabletService:
                try:
                    url = "http://www.google.com/"
                    if url == '':
                        self.logger.error("URL of the image is empty")
                    if not url.startswith('http'):
                        url = self._getAbsoluteUrl(url)
                    self.logger.info(url)
                    tabletService.showWebview(url)
                except Exception as err:
                    self.logger.error("Error during ShowImage : %s " % err)
                    self.onStopped()
            self.onStopped()