Displaying data collected from an external Database

Hello everyone,

as the title suggests, I am trying to use OpenHybrid for displaying machine-specific data (for example temperatures or whatever) . This data should afterwards be displayed in the RealityEditor as some kind of augmented reality GUI. My concept for this would be to create individual IO Points for every attribute I want to display (e.g. temperature, humidity…), dynamically create AR objects in the index.html and write the corresponding value from the database into that IO Point.

In the first step, I managed to connect the Arduino Yun, containing the OpenHybrid image, to a MongoDB Database and extract information out of it, using a Python Script which is called through another node.js script. Here I’ve encountered some issues as well, for example I tried to install different packets with the npm install command, but it failed with the error that I should call it with administrator privileges. I’ve SSHed into the Yun with the root account and even installed the sudo package with opkg to use the sudo command. Maybe there is a reason for this?

Furthermore, If I understood correctly here, the OpenHybrid image is blocking the Bridge function of the Arduino Yun, because it needs this communication path itself to exchange information beween the OpenHybrid server and the Sketch running on the 32U4.

I therefore wanted to ask if there is any way to pass the collected Information from the Database (lying around on the AR9331) and pass it on to the 32U4 to create the IO Points and to write the values in them. I am also not completely sure where the communication between the 2 processors is happening, but if I had to guess I’d say it is somewhere inside the server.js file.
I am quite new to node.js, that’s why I probably could not figure that out just by looking at your code.
I hope this is even possible at all!

Best regards!

Hi,

if I understood you correctly you just want to read data from the MongoDB database and expose that data as IOPoints and you don’t want to use anything Yun specific like the GPIO pins. If that is the case I would like to encourage you to use the beta_hardwareInterfaces branch and create your own hardware interface. The advantage of this approach is that you can run the software on any platform which can run nodejs (i.e. Windows, RaspberryPi,…) and you wouldn’t have to worry about how to get the data to the32U4 because you can create IOPoints directly in the nodejs code. An important detail is that you should use nodejs version 0.12.xx because the serialport package isn’t working on the newer versions. If you don’t use that package you could probably run it with a newer version, but i don’t know if anyone has ever tried it yet :wink:

You can find some information on how to create your own hardware interface here. If you need some more help, feel free to ask.

The communication between the 2 processors is happening in the arduinoYun hardwareInterface. It does indeed use the serial bridge function to communicate with the 32U4.

P.S.
Why don’t you simply use the MongoDB nodejs driver? Your approach with the python script sounds complicated :wink:

Hi Carsten,

thank you for your fast reply, it definitely helped me get started!
You got what I want to do. Once i have this data in IO Points, they should write that data into AR Elements in the Reality Editor. These Elements should furthermore get created dynamically depending on the Database entries. I was thinking about just generating the corresponding index.html file, I hope this works.

That sounds wonderful, I could therefore run that code with a Raspberry Pi (for example) as well then right? Thank you foryour help, I’ll be starting to implement my own hardwareInterface starting from next week then, and I’ll get back to you if I have any questions, and when I managed to achieve it. Maybe I’ll try to implement it so that other types of databases could be used, if that is possible for me. As I said, I am quite new to node.js

Yes you’re totally right, that would be less complicated, however I’ve tried to install the MongoDB node.js driver on the Arduino Yun using the npm packet manager, but this only resulted in an error message as stated here [quote=“Alex_Peitz, post:1, topic:338”]
I tried to install different packets with the npm install command, but it failed with the error that I should call it with administrator privileges. I’ve SSHed into the Yun with the root account and even installed the sudo package with opkg to use the sudo command. Maybe there is a reason for this?
[/quote]

Maybe you have an Idea? Interestingly, I was able to install the easy_install and pip packets for python, which then enabled me to install the python MongoDB driver on the Yun. I then used already existing libraries in node.js to connect to the database using python. When I’m back with the Hardware on Monday I could try again and post here the eventual error message :slightly_smiling:

Do you want to just expose your own webpage/service with DB access in to the reality editor?

Right now we only have the webpage delivered as a static page. But the goal would be that indeed we would be able to use any kind of web content such as pages that are connected with databases.
You could remove or replace the static/obj rout pointing to the objects folder in server.js L622 and point your own WebService to:
http://<ip>:8080/obj/<name>/

In general I had in mind to just generate a bar minimum nodejs server for such situations so that any other web service can easily be used to serve just AR web content on http://<ip>:8080/obj/<name>/ without the physical connection.

This is the minimum needed functionality:

  1. UDP broadcast on port 52316 an ID generated from a name + 12 char uniqueID like so:
    {"id":"<nameXXXXXXXXXXXX>","ip":"<xxx.xxx.xxx.xxx>"}
  2. Replay with a jason object (a) on
    http://<ip>:8080/object/<nameXXXXXXXXXXXX>
  3. (optional only for editing the size and position)
    Accept post messages (b) for changing the size “x”, “y”, “scale” and “matrix” in the jason object (a) on http://<ip>:8080/object/<nameXXXXXXXXXXXX>/size/<nameXXXXXXXXXXXX>/
  4. Eventually expose the web content on http://<ip>:8080/obj/<name>/

(a)

{
   "objectId":"<nameXXXXXXXXXXXX>", 
   "ip":"xxx.xxx.xxx.xxx", 
   "version":"<x.x.x>", 
   "x": <default 0>,
   "y": <default 0>, 
   "scale":  <default 1>, 
   (only if it has data) "matrix": [x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x],
}

(b)

{
   "x": <default 0>,
   "y": <default 0>, 
   "scale":  <default 1>, 
   (only if it has data) "matrix": [x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x],
}

What do you think?

Yes, exactly. That’s what I am doing at the moment. You can find installation instructions for the PI here

[quote=“Alex_Peitz, post:3, topic:338”]
Maybe you have an Idea? Interestingly, I was able to install the easy_install and pip packets for python, which then enabled me to install the python MongoDB driver on the Yun.
[/quote].

Sorry, I won’t be able to help you very much with Yun related topics because I am running everything on PI’s and on my laptop.

@valentin I like that idea. There are probably a lot of use cases, where you only want to visualize data and don’t really need to use the interconnectivity provided by the IOPoints. The RealityEditor is a convenient tool for placing and scaling the UI onto physical objects.

1 Like

Sorry for not being able to reply on the week end!

First to reply to @valentin:
Hm I’m not sure how the reality editor works I’m afraid, but I think that’s it. Dynamically generating new web content based on database entries. I guess generating the web content could be achieved in my own service.
Right now I was just planning on creating an index.html file while running my own node.js script with database access. I’ll have to look into your solution as well though!

@Carsten:
Okay thank you, I’ve already installed it on the Pi once before, but at that time I didnt get the concept of the different hardwareInterfaces.

Okay I’ll try to resolve it on my own then, but thanks anyways.

EDIT: [quote=“Carsten, post:2, topic:338”]
You can find some information on how to create your own hardware interface here. If you need some more help, feel free to ask.
[/quote]

I just wanted to access the documentation, but it seems like it is down right now. Can you confirm this?

EDIT 2:
I accessed the documentation directly via Github so that’s fine.

I’ve been encountering another error. It has something to do with the HybridObjectsHardwareInterfaces library. I get the following error:

C:\Users\8460p\Desktop\Alex\Uni\HiWi\OpenHybrid\Laptop Object\object-master>node server.js
got it started
Loading template: base
I found objects that I want to add
---
No saved data for: databaseObjecty6f2uu2ibt6b
 object null has no marker yet
UDP broadcasting on port: 52316
Sending beats... Content: {"id":"databaseObjecty6f2uu2ibt6b","ip":"134.61.84.192"}
socket.io started
C:\Users\8460p\Desktop\Alex\Uni\HiWi\OpenHybrid\Laptop Object\object-master\libraries\HybridObjectsHardwareInterfaces.js:5
<!DOCTYPE html>
^
SyntaxError: Unexpected token <
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (C:\Users\8460p\Desktop\Alex\Uni\HiWi\OpenHybrid\Laptop Object\object-master\hardwareInterfaces\databaseInterface\index.js:55:18)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

Some kind of syntax error, but I don’t know why I am getting this. You have any ideas? I downloaded the code from the hardwareInterfaces beta branch.

That’s weird. It seems your HybridObjectsHardwareInterfaces.js contains a line <!DOCTYPE html> which it shouldn’t. My guess is that it somehow got messed up when you installed it. How did you install it? Try the following:

git clone https://github.com/openhybrid/object.git
cd object
git checkout beta_hardwareInterfaces
npm install

@valentin The documentation seems to be down. Are you doing some maintenance work on the site?

Yes well it seems like the file did not get installed correctly at first.

I was using the tutorial here: Desktop & Laptop Computer
But when I downloaded the files there, the HybridObjectsHardwareInterfaces.js was missing. I then downloaded it separately from the git and used the npm install command. Seems like that didnt work out. Directly cloning the git was the way to go, thank you :slightly_smiling:

Seems like it. I will figure out whats the matter.

Ah, yes. The direct download is for some older version of the master branch. To create your own hardware interface you have to use the beta_hardwareInterfaces branch which is still under development and you can’t just copy the one file and hope it works :slight_smile: Quite a lot has changed.

But I’m glad I could help and you got it running.

Ok @valentin thanks!

@Carsten okay yeah got it, it actually did seem too easy but I didnt think about just cloning the git :smiley: I’ll keep that in mind from now on!

The documentation is back online.
I am also changing the category of this topic to developer.
Show and Tell is only for project you want to show and tell about. :slightly_smiling:

Ok so I got the basics working right now. I implemented my own, very very basic hardwareInterface (which should in theory be portable between systems that run node.js) where I connected to a MongoDB database and just read some parameters from a given document. I then write that parameter into an IO Point I’ve created before. Inside the index.html I just created a basic text element and request a read from that IO Point in a loop. In the obj.object.on() function I then write the value into the text elements innerHTML Property. This works fine, is very static though (hardcoding the IO Points and the read and write Operations from a Database).

@valentin:

So if I understand you correctly, you are saying that I could just write my own webpage with Database access, read the values from there, write them directly into the html elements and just display that page when connecting to the object via the RealityEditor? Or what do you mean by that? I’m sorry I’m very new to all that web programming stuff :sweat_smile:

Yes, I think you are using the IO-Points in a wrong way.
Because every time when you change a value from the IO-Point it gets processed by the ObjectEngine.
This means the system looks for links to other objects and in case the data is changed and linked, that data is send to another object.

It sounds like what you have in mind is a traditional Webpage with Database access.
So from that perspective you try to eat soup with a fork.

I suggested the following:

  1. In server.js L622 replace the static route with your own server responds.
    The server is based on nodejs express. You can model your database accesses via your own get and post server responses.
    You just need to make sure that your server responses are located in an “/obj” route so that the page you want to have augmented is accessible via http://<ip/domain>:8080/obj/

  2. Alternatively a simple way without even touching the server:
    You can just create an iFrame within the static page and the content of that iFrame can link to your own web server.

If you find a good solution that is working for you, could you create a small tutorial about it? I think it would be nice to show to others. :slight_smile:

Oh ok yeah that makes sense, it’s not the best way to do this then. [quote=“valentin, post:14, topic:338”]
It sounds like what you have in mind is a traditional Webpage with Database access.So from that perspective you try to eat soup with a fork.
[/quote]
Yeah now I understood, that’s basically it then. I didn’t know displaying AR stuff was as easy as just writing a web page . Would I still be able to move and resize the elements using the developer mode of the reality editor though? Or can I achieve that with what you said above about the json messages?

When I found a solution I’ll gladly write a tutorial about it! I think that using the Reality Editor like this could be a big application field as well.

Yes you will still be able to move the content via the editing mode.
The easiest way for you to work would be this:

  1. create a new object within the Open Hybrid web interface.
  2. include an iframe with a fixed width and height in to the static index.html page of your created object.
    (basically replace the bird.png image tag that you will find in that html page with your iframe.)
  3. link the iframe content to your own web server.

Only if you actually want to use the IO-Points to connect between objects, you will need to make changes to the server.js.

Example:

This is the page that will be generated by default when you create a new object:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
    <script src="object.js"></script>
</head>
<body>
	<img src="bird.png" width="300" height="300" alt=""/>
</body>
</html>

You can replace the img tag with an iframe tag that links to your own service:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
    <script src="object.js"></script>
</head>
<body>
	<iframe src="http://YOURSERVER" width="300" height="300" frameborder="0">
        </iframe>
</body>
</html>

Yeah ok that sounds pretty good, I’ll start by doing that! I’m implementing my own webservice right now, which can display data directly from a MongoDB database. I’ll tell you here when I managed to combine everything :slightly_smiling:

Thanks for your help!

Hello everyone, it’s me again. I just finished the basic implementation of my project to display data. Like @valentin suggested, I wrote some website which extracts the data from my database and then I generate a table using these entries. Inside the index.html of my object, I just have an iframe element linked to the website.

You wanted me to create a tutorial right @valentin? Where should I post this? Inside I would explain the basic concept and dynamics and explain the code I’ve written.

you can post the tutorial here itself @Alex_Peitz

Hi @Alex_Peitz. That sounds wonderful!
I am about to redesign the webpage and build it up on Wordpress.
The webpage will have a section for tutorials. For now, if you can just write it up with html format and post it here in the forum, that would help. I can then add it to the wordpress page later or give you write access.

What do you think?