Go Down

Topic: JSON WEB SERVER html (Read 8105 times) previous topic - next topic

pawqar


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!!

PeterH

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: [Select]

<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.
I only provide help via the forum - please do not contact me for private consultancy.

pawqar


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: [Select]

<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!!

PeterH

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"?
I only provide help via the forum - please do not contact me for private consultancy.

pawqar


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

SurferTim

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


pawqar


The client.println(" ") is not correct. That is not a blank line. It has a space. Try this.
Code: [Select]
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!!

Go Up