Hype and my Arduino board


(Jörg Wagner) #1

Hi,

I need to control my Arduino board form a running presentation made with hype. The presentation is running on chromes viewport.

for controlling the Arduino, I use an external .js file. node.js is also needed. From Terminal I can start the board by typing “node scriptlfile.js".

How to start node and execute the script file from hype?

Thanks in advance
Jörg


(Jonathan Deutsch) #2

I’d need to know a little bit more, but if you have a node server running, then you would typically communicate to this via an AJAX call within Hype (via a ‘Run JavaScript…’ action in response to say the ‘On Mouse Click’ handler).


(Jörg Wagner) #3

Hi Jonathan,

thanks for your reply. You’r right, but it seems to be too much complicated.

My task:

There is an exhibit including a touchscreen and an physically 3D printed model of the application in front. On the screen a presentation is running and a visitor can touch the screen to start an explanation, how the application is working. The presentation is easily made with hype (Yeah :slight_smile: and by touching the screen, a build-in motor moves the application to show how it works.

What I need is to trigger the motor to the visitors touch on the screen. The motor is controlled by an arduino and therefore I need a communication between the arduino and the presentation.

My Idea:

I will install a WEB-server on the arduino, which is waiting for a call from a client. If the call is comeing in (goto URL from hype) the arduino starts the motor.

This seems to be simple, no PHP or Ajax is needed?

Am I right? Im not sure what happens, if the call is repeated a second time? How to reset it?
What happens to the presentation, if the call (goto URL) is sended? How to terminate this request?

thanks for your suggestions in advance (everything will help :-))

Jörg


(Jörg Wagner) #4

Addition

I can stop the client on arduino very easy. How to avoid popup windows within hype?
Best
Jörg


(Jonathan Deutsch) #5

This sounds like a good plan. I would still use AJAX since the only alternative would be a ‘go to url’ handler, but that would literally tell the browser to change its address. The AJAX is a pretty short amount of javascript code to do the work on a ‘Run Javascript’ action. It would look something like:

function reqListener () {
  // do something if you need to deal with the response
  console.log(this.responseText);
}

var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", "http://10.0.1.128/action/path/on/arduino/");
oReq.send();

(of course substituting http://10.0.1.128/action/path/on/arduino/ with the URL for the arduino call)

This will just make a URL request silently in the background, so you don’t need to deal with popups or changing the navigation.


(Jörg Wagner) #6

Hi Jonathan,

thank so much for your suggestions. I will try out your example.

Jörg