473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can this be done with Javascript? Microcontrollers/TCP IP

Hi, I'm very new to Javascript so maybe my question could be stupid.

I'm playing with microcontrollers and a TCP/IP component.
This means that I can control electronics via TCP/IP, UDP and so on.
But, my problem is on the client side.

I want to have a program, or a web page containing buttons that, when
pressed sends a signal to the TCP/IP component and waits for a
response back.
Maybe this seems strange, but let's say I have a connection on port 80
and I click a radio button on a web page, the new information is send
(like with a "get" command) to the TCP/IP component.
That analyses the new command en sends a confirmation back.

In real this would be a web page that has 2 times 8 radio buttons that
sends information for 8 lamps.
The way the information is send by the Javascriot doesn't matter.
The TCP/IP component replies after the information is processed.

Lets say someone clicks "lamp1" from "OFF" to "ON"
The script should send a code that represents the state of the buttons
on the page
"A1,B0,C1,E0,F0,G0H0,I0"
This means that lamp A, C are ON, the rest is OFF.

The TCP/IP component checks if this can be done and replies:
"A1,B0,C1,E0,F0,G0H0,I0"
The same as the command send by the script.
The script reacts by visualize the new state.

In a later stage, the input should be a 8byte word.
So the 8 lamps should become textboxes that can contain numbers from 0
to 255.

This is but a draft version of this question, if it seems that
Javascript is not the best way to do this, I won't bother you anymore
:-)

Thanks for your help
Oct 16 '08 #1
11 6737
On Oct 17, 6:55 am, t...@testnospam.nl wrote:
Hi, I'm very new to Javascript so maybe my question could be stupid.

I'm playing with microcontrollers and a TCP/IP component.
This means that I can control electronics via TCP/IP, UDP and so on.
But, my problem is on the client side.

<snip>

This is but a draft version of this question, if it seems that
Javascript is not the best way to do this, I won't bother you anymore
:-)
It depends on what you mean by "best way". Best way for the
programmer, I'd say no. Best way for preventing a hacker from
switching lights in your house on or off, I'd say no. Best way to be
able to tell your client "Oh, just open the device's web page at
127.0.0.11 and click the red button", I'd say maybe.. depending on
what you mean by best...

The thing is, when it comes to communication, javascript can do only
what HTML can do: make HTTP requests. So first you'll have to make
sure your device can parse HTTP. And remember, the browser will not
send simple-and-minimal HTTP, rather it would send something like:

GET /set_buttons?A=1&B=0&C=1&E=0&F=0&GH=00&I=0 HTTP/1.1
Host: 127.0.0.11

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.17) Gecko/
20061201 Firefox/2.0.0.17 (Ubuntu-feisty)

Accept: text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive
Content-Type: application/x-www-form-urlencoded

message=1; current_style=1

Pragma: no-cache

Cache-Control: no-cache

Which is actually not that hard to parse. You'd only be interested in
the GET line and your device can ignore the rest. To test this out I'd
suggest first sending the data using a simple HTML form and don't
touch javascript until you can get your device to reliably talk HTTP.
Then, if you want, use javascript to make an AJAX request to avoid
having to reload the whole page.

Oct 17 '08 #2
On Oct 17, 12:55*am, t...@testnospam.nl wrote:
Hi, I'm very new to Javascript so maybe my question could be stupid.

I'm playing with microcontrollers and a TCP/IP component.
This means that I can control electronics via TCP/IP, UDP and so on.
But, my problem is on the client side.

I want to have a program, or a web page containing buttons that, when
pressed sends a signal to the TCP/IP component and waits for a
response back.
Maybe this seems strange, but let's say I have a connection on port 80
and I click a radio button on a web page, the new information is send
(like with a "get" command) to the TCP/IP component.
That analyses the new command en sends a confirmation back.
(...)

YES, no problem. This can be done in several ways. You can send/
request the info in the url of the http request of any resource
(usually an <imgor a <script>) as a query parameter '?q=theData' (or
not), and you can send/request it via an XMLHttprequest as well either
in the headers of a GET/POST/HEAD request or in the body of a POST
request.

HTH,
--
Jorge.
Oct 17 '08 #3
>It depends on what you mean by "best way". Best way for the
>programmer, I'd say no. Best way for preventing a hacker from
switching lights in your house on or off, I'd say no. Best way to be
able to tell your client "Oh, just open the device's web page at
127.0.0.11 and click the red button", I'd say maybe.. depending on
what you mean by best...

The thing is, when it comes to communication, javascript can do only
what HTML can do: make HTTP requests. So first you'll have to make
sure your device can parse HTTP. And remember, the browser will not
send simple-and-minimal HTTP, rather it would send something like:

GET /set_buttons?A=1&B=0&C=1&E=0&F=0&GH=00&I=0 HTTP/1.1
Host: 127.0.0.11

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.17) Gecko/
20061201 Firefox/2.0.0.17 (Ubuntu-feisty)

Accept: text/xml,application/xml,application/xhtml+xml,text/
html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive
Content-Type: application/x-www-form-urlencoded

message=1; current_style=1

Pragma: no-cache

Cache-Control: no-cache

Which is actually not that hard to parse. You'd only be interested in
the GET line and your device can ignore the rest. To test this out I'd
suggest first sending the data using a simple HTML form and don't
touch javascript until you can get your device to reliably talk HTTP.
Then, if you want, use javascript to make an AJAX request to avoid
having to reload the whole page.
I have a device that can react on everything that is send wit the GET
command.
So if the browser send this:

radiobuttons.html?A=on&C=on&G=on&Zend=Submit

I can filter out the names of the buttons and their state.
So all my device makes of it is:
A=on C=on G=on
The rest is ignored by the program in the controller.

But, my main question is if the controller can give feedback if the
lights were put on, and show this on the webpage.
So if I send the request to turn light A on, and the device checks if
the light is actually burning, this should be showed on the page.

This should be a two way communication.
Let's say that the lights were switched off by a switch in the room,
the controller knows that the light didn't turn on, and even if the
webpage requested to turn it on, after the command, shows the light as
dimmed.

Thanks already for your reply!!!
Oct 18 '08 #4
>YES, no problem. This can be done in several ways. You can send/
>request the info in the url of the http request of any resource
(usually an <imgor a <script>) as a query parameter '?q=theData' (or
not), and you can send/request it via an XMLHttprequest as well either
in the headers of a GET/POST/HEAD request or in the body of a POST
request.

HTH,
Thanks already for your reply.

Can you give me an example of how this works?
So if the "Send button" on the webpage is pressed, it parses (is this
the right word for send?) the information to the controller.

radiobuttons.html?A=on&C=on&G=on&Zend=Submit

The controller filters this request back to this:
A=on C=on G=on

Checks if this can be done (maybe the light is broken), and wants to
return the status back to the webpage.
What does the controller have to generate and send back, and how is
this processed by the webpage?

Again thanks!

Oct 18 '08 #5
On Oct 18, 3:38*pm, t...@testnospam.nl wrote:
>
Thanks already for your reply.

Can you give me an example of how this works?
So if the "Send button" on the webpage is pressed, it parses (is this
the right word for send?) the information to the controller.

radiobuttons.html?A=on&C=on&G=on&Zend=Submit

The controller filters this request back to this:
A=on C=on G=on

Checks if this can be done (maybe the light is broken), and wants to
return the status back to the webpage.
What does the controller have to generate and send back, and how is
this processed by the webpage?
It depends. Is that same device going to serve the .html page ?

--
Jorge
Oct 18 '08 #6
On Sat, 18 Oct 2008 15:31:31 -0700 (PDT), Jorge
<jo***@jorgechamorro.comwrote:
>On Oct 18, 3:38*pm, t...@testnospam.nl wrote:
>>
Thanks already for your reply.

Can you give me an example of how this works?
So if the "Send button" on the webpage is pressed, it parses (is this
the right word for send?) the information to the controller.

radiobuttons.html?A=on&C=on&G=on&Zend=Submit

The controller filters this request back to this:
A=on C=on G=on

Checks if this can be done (maybe the light is broken), and wants to
return the status back to the webpage.
What does the controller have to generate and send back, and how is
this processed by the webpage?

It depends. Is that same device going to serve the .html page ?
This is my initial idea to let the device hold the HTML page, but
because of lack of memoryspace in the device I think I must let go of
this idea.

So a page hosted on a different server would be a better idea.
Not only for this application, but also because of what you mentioned
earlier, security. I could prevent access to this page much better on
a webserver than on a chip.

So, if this page is hosted on a separate server, and I click a button,
a serie of signs are send (like with the GET command) to that IP
address. (or like in my second question, a byte)
Thing is that I would like to make this page fetch the actual state
back from the device.
If asked by the HTML-page, the controller would send back a value that
reflects the state of the outputs.

Again thanks!
Oct 19 '08 #7
On Oct 19, 6:35*pm, t...@testnospam.nl wrote:
>
So, if this page is hosted on a separate server, and I click a button,
a serie of signs are send (like with the GET command) to that IP
address. (or like in my second question, a byte)
Thing is that I would like to make this page fetch the actual state
back from the device.
If asked by the HTML-page, the controller would send back a value that
reflects the state of the outputs.
See my other post:
http://groups.google.com/group/comp....23c4a4093bde90

It is asking for a picture. You could get back the state encoded into
the size of the (dummy) picture that you return: the widht= hignibble
and the height= lownibble, for example ?

--
Jorge.
Oct 20 '08 #8
On Oct 20, 9:59*am, Jorge <jo...@jorgechamorro.comwrote:
On Oct 19, 6:35*pm, t...@testnospam.nl wrote:
So, if this page is hosted on a separate server, and I click a button,
a serie of signs are send (like with the GET command) to that IP
address. (or like in my second question, a byte)
Thing is that I would like to make this page fetch the actual state
back from the device.
If asked by the HTML-page, the controller would send back a value that
reflects the state of the outputs.

See my other post:http://groups.google.com/group/comp....23c4a4093bde90

It is asking for a picture. You could get back the state encoded into
the size of the (dummy) picture that you return: the widht= hignibble
and the height= lownibble, for example ?
Or, better yet, instead of requesting an <imgyou ought to request a
<script>, the script once received can setup any variables in you JS
code with ease. And then there's no need to build 'dummy' images at
the device, just a short string of text (the text of the script) will
do...

--
Jorge.
Oct 20 '08 #9
On Oct 20, 10:04*am, Jorge <jo...@jorgechamorro.comwrote:
just a short string of text (the text of the script) will
do...
Short like:

window.yourObject["deviceIP"].currentValue= "8a";
window.yourObject["deviceIP"].statusMessage= "The kitchen is on
fire.";

--
Jorge.
Oct 20 '08 #10
On Mon, 20 Oct 2008 01:11:59 -0700 (PDT), Jorge
<jo***@jorgechamorro.comwrote:
>On Oct 20, 10:04*am, Jorge <jo...@jorgechamorro.comwrote:
>just a short string of text (the text of the script) will
do...

Short like:

window.yourObject["deviceIP"].currentValue= "8a";
window.yourObject["deviceIP"].statusMessage= "The kitchen is on
fire.";
Thanks many times, will look in to it!!
Oct 20 '08 #11
On Oct 21, 12:27*am, t...@testnospam.nl wrote:
On Mon, 20 Oct 2008 01:11:59 -0700 (PDT), Jorge

<jo...@jorgechamorro.comwrote:
On Oct 20, 10:04*am, Jorge <jo...@jorgechamorro.comwrote:
just a short string of text (the text of the script) will
do...
Short like:
window.yourObject["deviceIP"].currentValue= "8a";
window.yourObject["deviceIP"].statusMessage= "The kitchen is on
fire.";

Thanks many times, will look in to it!!
I like that one so I've added it to my collection of "cljs
snippets" :-)

http://jorgechamorro.com/cljs/021/

--
Jorge.
Oct 21 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: richard green | last post by:
I have a huge text file which contains a list of all possible services that can be offered to the users. Let's say it looks like <services> <service>srv1</service> <service>srv2</service>...
2
by: Simon Wigzell | last post by:
I'm on a different computer running win 95 with IE 5 my website on a new dedicated server and I'm getting "Done, but with errors on page" appearing in the browser status area which I have never...
3
by: pentium77 | last post by:
Basically I have a situation where I need to update changes occuring in one Text field of a table into another text field located in another table. In addition both the tables are located in...
14
by: Evil Bastard | last post by:
Hi all, I'm currently tackling the problem of implementing a python to assembler compiler for PIC 18Fxxx microcontrollers, and thought I'd open it up publicly for suggestions before I embed too...
1
by: Empire City | last post by:
Hover Over Menu - Can this be done with C# or is it JavaScript? If JavaScript what would be the closest way to do something like this in C#, such as a drop down list box? If JavaScript is best does...
2
by: maya | last post by:
http://news.yahoo.com/news?tmpl=index2&cid=703 down the page, under "More Stories", there's a section with two interchangeable divs which slide back and forth into view.. how is this done? I...
3
by: maya | last post by:
http://www.msnbc.msn.com/id/16673873/site/newsweek/ pls scroll down, on the left, near the middle, there is a select object above which it says "Newsweek Business Directory".. how do they get...
12
by: Max | last post by:
Hi All, I need to check if attachEvent was done to an element. The problem is that attachEvent does not save this information anywhere. Is there any way to do this??? Thanks, Max
2
by: labmonkey111 | last post by:
I have a form that takes several seconds to run the javascript needed to prepare the form for PHP (selecting all items in a Select Multiple). Since it takes so long, I want to disable the Submit...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.