I am trying to control and receive data from my arduino over the web by using the serial port (serial=USB. I don't want to use Ethernet shield as I'm connecting the USB to an XBEE device).
After researching, I seem to believe the best approach will be javascript (PHP seems to be problematic with reading data from the arduino over serial).
Currently I'm trying to interface with the arduino using Processing.
I began with a simple script to read sensor data off the arduino which works fine when ran from processing (Java). when I try to export to view through a web browser (by using javascript in processing) I see everything in the browser except for the sensor data itself.
My understanding (more like a guess) is that for some reason the COM port will not open when called from the web browser (maybe security issue?). The same phenomena happens on both PC (WIN7) and MAC (OSX).
Help will be much appreciated!
Here is the code: (comments removed)
import processing.serial.*;
Serial myPort;
int xPos = 1;
void setup () {
size(400, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
background(0);
}
void draw () {
}
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
xPos++;
}
}
}
This may be dodging the issue but it sounds like you need to implement a layer of separation between the device and the HTTP service.
You could write a basic HTTP service using node.js or something that sits on the PC and arbitrates requests for data so that the request is not being made directly to the device from the browser.
It makes sense that a browser would strictly control client side JS access to hardware interfaces, if that is indeed what you're attempting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With