Pages: 1 [2]   Go Down
Author Topic: JSON WEB SERVER html  (Read 7407 times)
0 Members and 1 Guest are viewing this topic.
Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I want to show in a web page the values of my sensors.

The below is a more conventional and possibly easier method to display values in a web page.
...

Hi Zoomkat,

thank you for your time. I already know it, but I was asked to use JSON. I already did something similar...  http://g33k.blogspot.com/2010/09/arduino-data-webserver-sample-web.html

byes!!
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The JSON looks right to me.

To eliminate some of the complexity while you get the basic JSON-string-to-script-variable part working, try this:

Code:
<script>
  var json = {  name: "fio1"  };
  alert("json=[" + json + "]");
  alert("json.name=[" + json.name + "]");
</script>

That should pop up a message dialog saying json=[Object object], and json.name=[fio1], or something similar.

If not, then check for script errors when it runs.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The JSON looks right to me.

To eliminate some of the complexity while you get the basic JSON-string-to-script-variable part working, try this:

Code:
<script>
  var json = {  name: "fio1"  };
  alert("json=[" + json + "]");
  alert("json.name=[" + json.name + "]");
</script>

That should pop up a message dialog saying json=[Object object], and json.name=[fio1], or something similar.

If not, then check for script errors when it runs.

Hi PeterH,

I already did it on the example, and it shows " object Object" and it works:

name: fio1
temperature: 24
humidity: 85
address: 0x01
sleepCycle: 20
asynchronus: 0

but when I tried on the board, it said undefined ... maybe I explained myself badly. Sorry. Or I ´m not understand you xD

Anyway thank for reading my posts, I appreciate it.

Greetings!!
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This test code is intended to go in a HTML document on your PC, not involving the Arduino at all.

You should see a message dialog showing you the value of json and json.name. Do you see both of them? Does json.name show the correct value "fio1"?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This test code is intended to go in a HTML document on your PC, not involving the Arduino at all.

You should see a message dialog showing you the value of json and json.name. Do you see both of them? Does json.name show the correct value "fio1"?

Hi PeterH,

... Yes,sorry, my english it is no so good, well I pasted the code example I used it on my PC and it worked.  But, my question was about the arduino... As you see I deleted the open(get... etc, status, ...  and I simply write the json strutcture. It worked, an alert window appeared saying "object Object" and filling the gaps, name: fio1, temperature: 32 etc. That means that the example worked, the example I pasted on the post. So, with that,  I added the status, get, etc... but the alert window shows nothing and the gaps are filled with "undefined" but if I use the json structure { name: fio1, temperature: 34...} If I use {name: fio1, variables: { temperature: "32", humidity: "86"... etc}} it says something as unable to get temperature ...

sorry for my english

thanks
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 152
Posts: 6191
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The client.println(" ") is not correct. That is not a blank line. It has a space. Try this.
Code:
client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/plain");
  client.println("Connection: close");
  client.println();
  // rest of stuff
Logged

Santander
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The client.println(" ") is not correct. That is not a blank line. It has a space. Try this.
Code:
client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/plain");
  client.println("Connection: close");
  client.println();
  // rest of stuff


thank you!! it works !!it works!!

really thank you!!
Logged

Pages: 1 [2]   Go Up
Jump to: