Web browser a propeller and a com port = how?
Bits
Posts: 414
I would like to develop a webpage that communicates to the propeller on a com port. I don't want to send data over the net just commands from a web browser to a com port local machine style.
My idea is to use something like java to bring commands into the browser but I have no clue at this point if java can access a com port. Any ideas?
An example would be to create a button and when clicked it sends a command to the usb port where a propeller sits
Thanks
My idea is to use something like java to bring commands into the browser but I have no clue at this point if java can access a com port. Any ideas?
An example would be to create a button and when clicked it sends a command to the usb port where a propeller sits
<!-- HTML code--> <input type="button" value="Click me!" onclick="JavaScript:alert('Communicate to propeller here com 3')" />
Thanks
Comments
Install node.js. That is basically the V8 Java script engine from the Google Chrome browser that allows you to run JavaScript as command line apps.
Now install node-serialport. That allows you to then write a Javascript command line app that talks to the Prop over a serial link.
Now install socketio.js. That allows you to add a web socket server to your JavaScript app in about 10 lines of code. That websocket server can relay serial data from the serial port to a web page in a browser.
Now write a web page including some Java script that connects to the web socket server and dislplays the data how you like. Can also send data back to the prop.
Ther you have it, prop to web page with no web server in the middle.
I was about to start a thread on how to do this as it is so simple to create a gui app in a web page talking to your local prop this way.
It does Web pages, Telnet, has 1-wire, a RTC, an I-button socket, CANbus, and more.
http://www.maxim-ic.com/app-notes/index.mvp/id/2792
If you want, you could hang a Propeller on one of the two RS232 ports or connect via I2C
http://www.maxim-ic.com/datasheet/index.mvp/id/3609
Focus on the evaluation kit as the motherboard provides the RTC which is important.
http://www.maxim-ic.com/datasheet/index.mvp/id/4983
And since I see that these are NO LONGER AVAILABLE, I could sell you one at my cost. The biggest advantage is this can be on 24/7 without passing through your desktop computer and it is very low power.
I've been playing with socat (a netcat utility on steroids) to make my USB connected propeller visible as an IP address and a port so I could use socket I/O to talk to it. I figured almost everything can support IP:port type I/O in one fashion or another but sometimes pure serial port I/O is hard to find.
It has worked well in my limited testing. I am able to hang a Propeller off a USB port and then map its serial port (COMx: or /dev/ttyUSBxx) to an IP port. OK, now here's the painful part for most folks. My Propellers are often running PropForth, so once socat is running, I can telnet to my PropForth session from the local host or any host on the network. Plus, I can write programs that do socket I/O and carry them from OS to OS more easily without worrying about the com port support or go from language to language without scrounging for a serial library (most everything supports socket I/O).
The next step is to replace the USB with Bluetooth or Wixel and go wireless.
Your experiences may vary but it's worked for me so far. Search for socat, it's available for most linux distros and also there is a Windows version.
[EDIT: Ooooh, I like Heater's solution! I'll patiently wait for his demo thread about node.js]
Its has to be windows, Linux would have to come later. It also would have to run on all browsers so would java indeed be best avenue to proceed? Ill have to learn java but I want to make sure its the best choice.
I would also like to create a plots that receives data from the propeller PCB I designed.
absorbance vs. wavelength (nm)
Temperature vs. time
etc.
The beauty of node.js is that you can write that 50 lines or so to connect between browser and serial port in the same language, Javascript, so not too many things to learn.
The only reason I say Linux is that while node.js runs on Windows I'm not sure yet if the serial port module works on Windows yet.
That socat solution sounds like the linux ser2net that moves data from a serial port to a socket connection. But that still leaves the problem of connecting to a web page. Unless your prop implements HTTP and perhaps the web socket protocol
Which sounds like a bit much to ask.
socat = bad solution!
node.js = good solution!!
Now that I know what to call it:)
Attached is a program that will do what you want. It runs from a console window, but you can create a Windows shortcut for it, once you have determined the correct parameters to run it. Type serial_data_server without arguments for a help screen that describes the parameters that it takes. Once started, it creates a link between an IP port and a serial port on the same computer. To halt the server, hit Ctrl-C in the console window.
Here is a simple web page that illustrates its use. You will have to change the part in red to match your own server's address:
Here is a Prop program that responds to requests from the above webpage. It should be stored in EEPROM, since the server may reset the Prop when started or stopped.
BTW, the program also works to receive data from the Prop. Anything the Prop sends after receiving data from the server, and before a 100 ms timeout, gets sent back to the browser as an HTTP text/plain document.
-Phil
So far this looks cool but here is what I am wondering.
I have my PC and next to it is the propeller device. Do I still need an ip-address on the client side of things? Can I use 127.0.0.1 as a substitute?
That is a good solution in many simple cases.
It does require that your Prop implements HTTP and the web pages that it serves up.
What if you want a web page that displays a real time graph of various measurements the Prop is making? Say temperture, pressure, acceleration, whatever.
Then your Prop is full of code doing that and only producing a simple telemetry stream over serial.
Then what if you want command back to the Prop to control this and that?
At that point you have a serious web server in the Prop which it does not have space to handle.
Putting a little inteligence in the PC gives you the chance to have simple data out from the Prop and simple commands back to the Prop. All the heavy lifting happens in the browser. Perhaps even 3d visualization of the data the Prop is producing with webgl.
With node.js and web sockets you can get real time display. I have a system doing this that updates the web page graph 10 times per second.
I run the server doing the following
I type
I keep getting an error. Where did i go wrong?
Error states
Missing or invalid comm parameter
Heater you bring up a good point but I have to test Phils code nevertheless.
It's comm, not com.
-Phil
In that case, use HTML5 and Ajax techniques with Javascript to draw the graph in a canvas object from the raw data that the Prop returns. There really isn't much need these days for fancy servers to mediate the presentation.
-Phil
Yes HTML5 and AJAX.
But my plan is HTML5 and a dead simple websocket connection.
There is no fancy web server, if you are doing this locally on your PC, only a few tens of lines of Javascript running under node.js and your browser picking up the web page from a file in your local file system.
No more onerous than using a Perl script as an intermediory.
'Sorry I missed your first question. Yes, you can use 127.0.0.1, followed by a colon and the port number, e.g. 127.0.0.1:12345. For some reason, Windows does not like localhost, though.
-Phil
Time to go home have some wine, relax in a hot bath and read data sheets! Yea.
The correct way for you to start the program, based on what you've told me so far is:
In your webpage, the line that specifies the host address would read:
-Phil
Got a new error states
I think its time to learn javascript. Thanks for giving me a shot at it.
You give up too easily. The program is doing what it's supposed to. Access was denied to COM70, either because another program on your PC is using it, or because there's no device with that number plugged into the machine. In the former case, stop the other program that's using it, and try again. In the latter case, make sure the Prop is plugged in, and use F7 in the Prop Tool to find the correct COM port number. (Ignore the other garbage that came after. There's an error-reporting module missing from the exe, but that's a non-issue when you're connected properly.)
-Phil
I did not give up but found that com 70 is being used by another prop. :frown: Ill do again this time com 25. Thanks
Questions
1, is the source code available for the server program?
2, can I create a text box on the webpage and send the number to the server program? Floating and non-floating values?
1. Yes, attached with a new version of the exe that includes the missing module.
2. Yes, yes, and yes. The data are sent to the Prop as text, so your Spin program will have to convert the ASCII to the values you want to use. Sending text from a text box (i.e. <input> tag) requires accessing it in the DOM and retrieving the value property when a Send button is pressed. I would bypass the usual form/submit routine, because that will entail waiting for and displaying a response from the server, and you don't want your original webpage to go away So you will have to do it in JavaScript.
-Phil
How would I connect through a gateway. I see the webpage has this ip address
But this is my network ip-address my real ip address is something closer to 208.89.163.80
-Phil
Where can I obtain the source code? The attachment you left is only executable form.
-Phil
If I see that if this will work out, I would like to somehow make an application that can install the FTDI driver and scan the PC ports, find my spectrometer PCB (using the propeller I might add, and boy do I need a prop II soon) and connect to it.
Again thanks.
BTW, here's an HTML file that shows how to send data from a text field:
Here's the Spin program that it controls:
-Phil