Controlling Arduino Relay with HTML/JAVA hosted on desktop. Serial or Ethernet?

Hi,

I've been asked to look at a project to solve that wasn't very planned out from a design point of view. 3x separate teams/people worked on their own sections with out realizing they needed to be linked. I've been asked to have a look and see if I can come up with a solution. With time, I think I could probably google and learn my way to it, however my schedule has been pushed forward so I would appreciate some help.

I have a touchscreen Kiosk Win 10 PC as part of a larger display, that is running a HTML5/Java/JQuery interactive page - very simple, menu has 6 buttons, select a button and it plays a corresponding video then returns to the main menu.
While the video plays, they would like a light to be illuminated showing the correct area of the display for the video that is playing. IE; Video 3 = Light 3

My initial thought was to use to send a signal to an Ardunio Uno via serial/COM port with the button press which triggered a pin to an 8ch Relay unit to run the lights.

While getting this to work locally with serial monitor and trigger the relay was simple enough, once I started looking into the connection to the main HTML/Java environment, I found I would need something like Node.js to run as a middle man.

The other option I had considered was could I use an Web Server, either using a Ethernet Shield or ESP8266 Wifi to host a web client (or something) to capture a playback trigger via PHP or WebSocket or something similar.

Or is there a way to broadcast a signal/command directly (say '>4a') from the Kiosk HTML/JAVA via Ethernet/WiFi to the IP/MAC address of the Arduino and have that trigger the correct relay.

Ideally I'd like to use a WiFi option for neatness on the Kiosk install (no USB/Ethernet cable hanging out the bottom of the screen/All-In-One-PC), but anything that gets it working is better than nothing.
I do not think I need 2-way communication for anything. Only to trigger the relay. No sensors or data readouts.
I just want to be able to boot the Kiosk and Ardunio and have it work day after day.

I currently have an;
Arduino Uno R3 with Ethernet Shield
Arduino Uno R3 (copy) with integrated ESP8266 WiFI
8ch Relay Board

Any help or suggestions will be appreciated and tried.

TL:DR
What is simplest/reliable way to take a control signal from an externally hosted (same LAN) HTML/JAVA webpage to an Arduino Relay. Receive data only, no need for 2-way communication. Max 7 independent triggers. 6x Specific Relay On and 1x All Relay Off.

the Java runs on the PC and has access to virtual COM port to Arduino Serial

You might get one or two of the below WeMOS D1 development boards and start experimenting with wifi setups. Lots of tutorials available for using the bESP8266 for web page control of relays.

https://www.ebay.com/itm/OTA-WeMos-D1-CH340-WiFi-Arduino-UNO-R3-Development-Board-ESP8266-ESP-12E/383124613310?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

Juraj:
the Java runs on the PC and has access to virtual COM port to Arduino Serial

Can you clarify? My understanding is browser based Javascript can't access any hardware (other than keyboard/mouse ect) without needing something to intercept the data (such Node.js) and pass it on to a physical port, such as a USB-Serial, to the Arduino unit. Is that correct, or have I misunderstood something.

If I do need to use something like Node.JS, then I will need to get it properly communicating, and then make it into a script that will run on boot up with the kiosk browser.

I'm willing enough to give it a try, I'd just like to make sure I'm going down the correct rabbit hole before I commit many hours into it.

zoomkat:
You might get one or two of the below WeMOS D1 development boards and start experimenting with wifi setups. Lots of tutorials available for using the bESP8266 for web page control of relays.

https://www.ebay.com/itm/OTA-WeMos-D1-CH340-WiFi-Arduino-UNO-R3-Development-Board-ESP8266-ESP-12E/383124613310?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

I do already have a Uno R3(compatible) with WiFi board with an ESP8266 chip. https://www.jaycar.com.au/uno-with-wi-fi/p/XC4411

Any reason I should get the one above? Is it different?

Also, most of the tutorials I have found so far are for locally hosted relay switching. All the HTML and Javascript are stored directly on the Arduino or ESP8266/variant chip. And they work perfectly. I can happily turn the relay on and off via my phone/laptop using a basic html page and some buttons hosted off the ESP8266.

I need the website/browser to run directly off the Kiosk PC and feed the control to the Arduino. Do you know of any tutorials for that?

cnoppers:
Can you clarify? My understanding is browser based Javascript can't access any hardware (other than keyboard/mouse ect) without needing something to intercept the data (such Node.js) and pass it on to a physical port, such as a USB-Serial, to the Arduino unit. Is that correct, or have I misunderstood something.

If I do need to use something like Node.JS, then I will need to get it properly communicating, and then make it into a script that will run on boot up with the kiosk browser.

I'm willing enough to give it a try, I'd just like to make sure I'm going down the correct rabbit hole before I commit many hours into it.

Java is not Java Script. ("Java is to JavaScript like ham to hamster").

how are the web pages served to browser? is there some web application on server or only a http server?

Couple things...

1.) I dont have any experience with Node.js so I wont be including that in anything I talk about.

2.) Java != Javascript.. Not sure who or where that came from.. but it needs to be clear.. and we need to use the correct naming conventions.

3.) Can we clarify (maybe I missed it?) abotu HOW this Windows 10 PC is set up?

  • You say it Running an HTML5/Java??/jQuery page...

  • Java means javascript then? or real Java?

  • What does 'running' mean? Its a bit confusing as to what 'running' means.. because later you talk about installing a 'Web Server'??

It this just a static HTML page running locally of the desktop or something?? Or do you have web server software installed so it run say PHP scripts or have a database..etc..?

If you do NOT need two way communications..

this is an easy set-up IMHO..

  • Install WAMP server
  • Create 'web page'
  • Upon page submission (of you can use AJAX if you dont want to submit the whole page) you call/execute a simple PHP script (I'm more familiar with PHP, so that is my go-to language) that sends out the data via COMM PORT.
  • Your connected Arduino will 'listen' for any incoming serial data, parse it, and behave as you code it to, when an incoming action/command if sent.
1 Like

"Any reason I should get the one above? Is it different?"

If the uno with the ESP8266 chip work together seamlessly without a lot of extra effort, then that should suffice.

Juraj:
Java is not Java Script. ("Java is to JavaScript like ham to hamster").

how are the web pages served to browser? is there some web application on server or only a http server?

The single page is hosted locally C:/ on an All-In-One TouchScreen Win 10 Desktop PC, running KioWare kiosk software, which is effectively Google Chrome with a full-screen lock. I do have full access to the PC for setting up.

Apart from some HTML and CSS formatting, the page consists a jquery script to run 6x fullscreen videos on button click and return to home/menu either at the end of playback, or if a home button is clicked.

xl97:
Couple things...

1.) I dont have any experience with Node.js so I wont be including that in anything I talk about.

I also have none, hence wanting to make sure about suitability for purpose before I try to get in to deep.

xl97:
2.) Java != Javascript.. Not sure who or where that came from.. but it needs to be clear.. and we need to use the correct naming conventions.

That's my mistake, I'll blame it on being tired, but I should know better

xl97:
3.) Can we clarify (maybe I missed it?) abotu HOW this Windows 10 PC is set up?

  • You say it Running an HTML5/Java??/jQuery page...

  • Java means javascript then? or real Java?

  • What does 'running' mean? Its a bit confusing as to what 'running' means.. because later you talk about installing a 'Web Server'??

It this just a static HTML page running locally of the desktop or something?? Or do you have web server software installed so it run say PHP scripts or have a database..etc..?

The single page is hosted locally C:/ on an All-In-One TouchScreen Win 10 Desktop PC, running KioWare kiosk software, which is effectively Google Chrome with a passworded full-screen lock. I do have full access to the PC for setting up.

Apart from some HTML and CSS formatting, the page consists a jquery-3.4.1 script to run 6x fullscreen videos on button click and return to home/menu either at the end of playback, or if a home button is clicked.

Having everything stored locally on the desktop is beneficial;
1: for initial buffering as the videos are approx 350mb
2: in the event something doesn't work/breaks or gets unplugged the Kiosk side still continues to run normally with out the display lights.

xl97:
If you do NOT need two way communications..

this is an easy set-up IMHO..

  • Install WAMP server
  • Create 'web page'
  • Upon page submission (of you can use AJAX if you dont want to submit the whole page) you call/execute a simple PHP script (I'm more familiar with PHP, so that is my go-to language) that sends out the data via COMM PORT.
  • Your connected Arduino will 'listen' for any incoming serial data, parse it, and behave as you code it to, when an incoming action/command if sent.

I can not think of any reason I need two way communications.
I did look into a WAMP server, through my various googlings, and it looks like it should serve my purposes. My concern was that WAMPs documentation said it was very bad to shut it down without closing everything properly and could cause config issues/corruption. I can't control how this unit will always be turned off. For all I know they may just decide to unplug it from the wall at the end of the day.

I'll look into learning more about PHP and AJAX, do you know of any tutorials/examples that would help my specific situation.

Here's the kiosk page code, if that is any help.

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <meta name="copyright" content="Bluntmedia 2020">
  <meta name="language" content="EN">
  <title>Bridges</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>

  <div id="tabs-menu">
    <a class="video-tab" id="vid-1" href="JavaScript:Void(0);"></a>
    <a class="video-tab" id="vid-2" href="JavaScript:Void(0);"></a>
    <a class="video-tab" id="vid-3" href="JavaScript:Void(0);"></a>
    <a class="video-tab" id="vid-4" href="JavaScript:Void(0);"></a>
    <a class="video-tab" id="vid-5" href="JavaScript:Void(0);"></a>
    <a class="video-tab" id="vid-6" href="JavaScript:Void(0);"></a>
  </div>

  <div id="tabs-content">
    <button class="modal-close" >MENU</button>
    <div id="modal-1" class="modal">
      <video id="video-1"><source src="video/1_1.mp4" type="video/mp4"></video>
    </div>

    <div id="modal-2" class="modal">
      <video id="video-2"><source src="video/2_1.mp4" type="video/mp4"></video>
    </div>

    <div id="modal-3" class="modal">
      <video id="video-3"><source src="video/3_1.mp4" type="video/mp4"></video>
    </div>

    <div id="modal-4" class="modal">
      <video id="video-4"><source src="video/4_1.mp4" type="video/mp4"></video>
    </div>

    <div id="modal-5" class="modal">
      <video id="video-5"><source src="video/5_1.mp4" type="video/mp4"></video>
    </div>

    <div id="modal-6" class="modal">
      <video id="video-6"><source src="video/6_1.mp4" type="video/mp4"></video>
    </div>

  </div>

  <!-- ============= Background Image  =============  -->
  <img id="bg-image" src="navigation-home-screen.jpg" alt="Background">
  
  <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>

  <script>
    // open modal and play video
    $('#vid-1').on('click', function() {
      $('#modal-1').show();
      $('#video-1').get(0).play();
    });
    $('#vid-2').on('click', function() {
      $('#modal-2').show();
      $('#video-2').get(0).play();
    });
    $('#vid-3').on('click', function() {
      $('#modal-3').show();
      $('#video-3').get(0).play();
    });
    $('#vid-4').on('click', function() {
      $('#modal-4').show();
      $('#video-4').get(0).play();
    })
    $('#vid-5').on('click', function() {
      $('#modal-5').show();
      $('#video-5').get(0).play();
    });
    $('#vid-6').on('click', function() {
      $('#modal-6').show();
      $('#video-6').get(0).play();
    });

    $('.video-tab').on('click', function() {
      // $('img#bg-image').animate({opacity: 0, duration: 1000 }).animate({opacity: 1, duration: 1000 });
      $('.modal-close').animate({opacity: 1, duration: 1000 });
    });
    
    // Close modal and sop all video
    var modalClose = $('.modal-close');
    modalClose.on('click', function() {
      $('img#bg-image').css({opacity: 0}).animate({opacity: 1, duration: 1000 });
      $('.modal-close').animate({opacity: 0, duration: 1000 });
      $('.modal').hide();
      $('div.modal video').each(function(){
        this.pause();
        this.currentTime = 0;
      });
    });

    // Close modal on video end
    var jqueryVideo = $('video');
    jqueryVideo.on('ended', function() {
      $(this).parent().hide();
    });

  </script>

</body>
</html>

zoomkat:
"Any reason I should get the one above? Is it different?"

If the uno with the ESP8266 chip work together seamlessly without a lot of extra effort, then that should suffice.

So far I haven't run into any issues, just flick a dip-switch or 2 depending which components need to be communicated with/uploaded to and it works fine.

@zoomkat

What approach are you suggesting that uses 1 (or more) ESP8266 modules?

Are you saying to have the ESP's host the website/be the web server?

Which is def doable.. but he has a 'PC' already... (I'm just not clear on what your approach is?)

@cnoppers

Apart from some HTML and CSS formatting, the page consists a jquery script to run 6x fullscreen videos on button click and return to home/menu either at the end of playback, or if a home button is clicked.

None of which has the ability natively to communicate to the serial/comm ports..

If this was running in a web host environment, you could add in some jQuery/AJAX calls to an external PHP script that would send the serial data out to the connected Arduino to toggle whatever light is needed.

I did this (almost) exact same things many years ago.. expect my front end was a FLASH and not HTML based at the time.

I have two current projects that do more or less the same (but more advanced as I needed two communication which wasnt possible with a Windows machine)..

So I have a Raspberry Pi running as my web server and my display..

  • Iron Man HUD project (live streaming video overlaid with graphics/animations and real time data displays from external Arduino circuits) - This is (again) FLASH (yes its old and dead, but was a perfect fit here) and some XML socket communication

  • Another Raspberry Pi as my host and HDMI display

  • HTML/CSS/jQuery-AJAX/PHP/MySQL based.. where I have a front end GUI for the user to scroll through, pick an option (its a drink menu).. and then I send out the 'drink recipe' out via PHP via comm port.. my (USB) connected Arduino then parses this incoming data, and moves some steppers/servos around to actually dispense/make the drink the user 'ordered'.

So this is all definitely possible... :slight_smile:

re: WAMP documentation.

I guess I dont really shut down my PC often..

but I have never had an issue with WAMP being corrupted by out of the blue 'shut-downs' or reboots..

For me..... that would have been one of the last things I would worry about. (but I cant comment on much of a risk can be taken I guess? I just have never had any issues)

As far as the PHP/AJAX stuff.. I dont have any specific tutorials in mind off hand..

but because you are already utilizing jQuery (somewhere) in your project... this would be a simple 'additional' call that would be added.... (I'm guessing in the same function/action that gets executed when a button is clicked?)

and then a PHP script that does the serial port communications. which is pretty simple too.. just takes the 'posted' data and sends it out via serial port.

You still need to have a connected Arduino, and some code that listens/parses this incoming data/protocol...

and do whatever with it (toggle lights...etc)

xl97:
None of which has the ability natively to communicate to the serial/comm ports..

If only it could...

xl97:
If this was running in a web host environment, you could add in some jQuery/AJAX calls to an external PHP script that would send the serial data out to the connected Arduino to toggle whatever light is needed.

I did this (almost) exact same things many years ago.. expect my front end was a FLASH and not HTML based at the time.

I have two current projects that do more or less the same (but more advanced as I needed two communication which wasnt possible with a Windows machine)..

So I have a Raspberry Pi running as my web server and my display..

  • Iron Man HUD project (live streaming video overlaid with graphics/animations and real time data displays from external Arduino circuits) - This is (again) FLASH (yes its old and dead, but was a perfect fit here) and some XML socket communication

  • Another Raspberry Pi as my host and HDMI display

  • HTML/CSS/jQuery-AJAX/PHP/MySQL based.. where I have a front end GUI for the user to scroll through, pick an option (its a drink menu).. and then I send out the 'drink recipe' out via PHP via comm port.. my (USB) connected Arduino then parses this incoming data, and moves some steppers/servos around to actually dispense/make the drink the user 'ordered'.

So this is all definitely possible... :slight_smile:

I was actually reading through that project last night (I only just realized you were the same user).

xl97:
I guess I dont really shut down my PC often..

but I have never had an issue with WAMP being corrupted by out of the blue 'shut-downs' or reboots..

For me..... that would have been one of the last things I would worry about. (but I cant comment on much of a risk can be taken I guess? I just have never had any issues)

That is going to be good enough to at least give it a go.

xl97:
but because you are already utilizing jQuery (somewhere) in your project... this would be a simple 'additional' call that would be added.... (I'm guessing in the same function/action that gets executed when a button is clicked?)

and then a PHP script that does the serial port communications. which is pretty simple too.. just takes the 'posted' data and sends it out via serial port.

It's starting to look a lot more compartmentalized, so I really do appreciate the guidance. I've got WAMP already installed, so it's time to figure out how to make that work for my purposes and I'll start looking for the simplest method of creating a button click call, and a simple PHP to handle the next steps.
The Arduino is already working fine on serial communication (as well as Ethernet/WiFi) I can already control all the relays, so its just a case of sending the correct trigger to it from the PHP script.

"Are you saying to have the ESP's host the website/be the web server?"

Pretty much. I'm just trying to see the real issue thru all the web stuff forest. What I see is the OP has a windows 10 tablet that does a lot of stuff already, but he/she needs a button(s) on the GUI screen to turn on/off lights that are remote to the tablet. If I was doing something similar, I would try putting an AP web server on an ESP8266 board. Then it can receive commands wirelessly from a web page on the tablet to operate lighting relays connected to the ESP8266 board. This is a very common setup. Set the tablet to auto connect to the ESP AP. The commands could be hard coded in the tablet page and the ESP would not have to serve a web page. It is hard to tell just what has actually been tried.

ok.. I just wasnt clear what your approach was.

I have done that many times.. configured my ESP's as captive portals and hosted my own 'web page'

Submit, parse the $_POST data and 'do whatever'

I just wasnt aware that he couldnt use this 'kiosk software' stuff and the current 'Windows 10 PC'

cnoppers:
If only it could...

I was actually reading through that project last night (I only just realized you were the same user).

That is going to be good enough to at least give it a go.

It's starting to look a lot more compartmentalized, so I really do appreciate the guidance. I've got WAMP already installed, so it's time to figure out how to make that work for my purposes and I'll start looking for the simplest method of creating a button click call, and a simple PHP to handle the next steps.
The Arduino is already working fine on serial communication (as well as Ethernet/WiFi) I can already control all the relays, so its just a case of sending the correct trigger to it from the PHP script.

Can you share the front end markup?
Like the 'code' (jQuery?) that the buttons call/execute when clicked?
Also (in plain terms)..can you explain what happens when a button is clicked?

  • does it 'submit' the page? or do any kind of $_POST action?
  • does is just call some javascript/jQuery functions to load/play some video? (using some API of some kind perhaps?)
    I can probably throw something together for you if I can see whats going on a bit more, and understand when things needs to be executed..etc..

something like this?

it may be simpler if the page is a local file

How do these ESP hosted solutions fit into the requirement of:

1: for initial buffering as the videos are approx 350mb
2: in the event something doesn't work/breaks or gets unplugged the Kiosk side still continues to run normally with out the display lights.