MKR 1010 high-speed data-transfer from client to server

I'm using an MKR 1010 WiFi to control a piece of medical test equipment. This requires a lot of control by the user and what I'm doing now is using the Arduino as a web server to put up a user-interface web page across a local network. The page has lots of numeric-input fields and every increment or decrement click sends data to the Arduino server which then does the right thing with the medical machinery. All this works as expected. (All this has to have the controls wirelessly detached from the medical machinery--this is radiation oncology stuff that sprays dangerous amounts of radiation all though a room with metre-thick walls.)

The problem is that every HTML POST or GET that results from clicking the buttons causes a screen reload which not only slows things down but also makes the screen flash a lot. The question is if there's a way to send that client data to the Arduino that doesn't cause a reload and is therefore faster and doesn't cause flicker.

I was looking into the WiFiNINA library UDP functions, but apparently browsers block that as some kind of security problem. Javascript AJAX didn't seem to do what I want, and I can't find a clue how to get node.js to work, or even if it's the right thing.

Any advice would be greatly appreciated.

Thanks,
Chris Moller

The crystal ball doesn't show Your code, Your wiring, nothing. Can You help us with that?

Basically, there is no wring, just an MKR 1010 and an MKR Connector Carrier with six servos plugged into it. Most of the code, about 500 lines of it, is a lot of fairly elaborate math that takes deflection and attitude input from a user through an HTML form on a browser and uses that to control the servos for what's called a Stewart platform (which is holding up biological samples being zapped by intense radiation of various sorts.)

The code is lots of variations on:

 client.println ("<form id=\"position\" method=\"get\" \
            onchange=\"createURL(this);\"		       \
            onkeypress=\"return keyHandler(this);\"            \
            >");
client.print ("<input type=\"number\" id=\"pdx\" size=\"4\">  ");
client.print ("<input type=\"number\" id=\"pdy\" size=\"4\">  ");
etc.

onchange and onkeypress eventually result in:

window.location.href = rc;

where rc is a long string containing a lot of information.

The problem is that every up-click and down-click on all these input fields causes a screen reload when all I really want to do is get the server to do all that math and do the right thing with the servos to move the Stewart platform the right way. No feedback to the browser/HTML required at all.

So the question is, is there any way to do just a one-way communication, client to server, that doesn't result in a reload? AJAX looked promising, but if there's a way to make that work with Arduino, I can't find it, and pretty much the same thing with node.js

Solved.

Got through the maze with AJAX; the solution is to eliminate the onchange attribute from the form element and add onchange="updateParam(this);" to the input element where updateParam() is defiined as:

client.println ("function updateParam(el) {");
client.println ("  const XHR = new XMLHttpRequest();");
client.println ("  var text = window.location.origin + \"?update=\" + el.id + \"=\" + el.value;");
client.println ("  XHR.open('POST', text);");
client.println ("  XHR.setRequestHeader('Content-Type', 'text/plain');");
client.println ("  XHR.send();");
client.println ("}")

Sorry I'm a bit late, but I created an AJAX demo using the WiFiNINA module just because like you, I couldn't find a good illustration of how to get AJAX working with the WiFiNINA. I used the Nano RP2040 Connect not the MKR 1010, but they both use the u-blox NINA-W102 module.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.