Jump to content

Javascript Help

Go to solution Solved by SSL,
Okey so here is the code, its almost exactly the same as yours exept i cant get mine to work.

 

Your access to the elements of the data objects is wrong. Should be something like so:

data.with[0].createddata.with[0].content.temperature

Hello,

 

I need some help with a project of mine, I've been trying to find a solution for it for some time but might have found it, but I need some coding help. The code I need help to write is in javascript, I'm going to try to explain.

 

Okey, my goal is to display sensor data on my webserver that comes from my arduino, from the arduino i have the data uploaded/sent by a program/api that is called dweet.io (http://dweet.io/) from here I can get the data by typing in my "thing" name in the browser, but what i need help is to create a easy way to get this data from a javascript file and then display it a bit nicer on my server. On there website there is a lot of documentation on how but i cant figure it out. So if someone knows how this works i would be very happy to get some help. 

 

 

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

What are you running on your webserver to display the code? Flat HTML and Javascript? jQuery? Or do you have serverside code going on?

Link to comment
Share on other sites

Link to post
Share on other sites

What are you running on your webserver to display the code? Flat HTML and Javascript? jQuery? Or do you have serverside code going on?

What is jQuery different than being a Javascript library?

Link to comment
Share on other sites

Link to post
Share on other sites

What is jQuery different than being a Javascript library?

 

Nothing? I don't understand the question. It is a Javascript library.

Link to comment
Share on other sites

Link to post
Share on other sites

Nothing? I don't understand the question. It is a Javascript library.

Why did you mention them serperately?

Link to comment
Share on other sites

Link to post
Share on other sites

Why did you mention them serperately?

 

Because they are separate. jQuery is written IN Javascript, but it is not part of the core Javascript that ships with browsers. You can write Javascript all day long without using jQuery.

Link to comment
Share on other sites

Link to post
Share on other sites

What are you running on your webserver to display the code? Flat HTML and Javascript? jQuery? Or do you have serverside code going on?

I dont have it fully setup at the moment but i have php (HTML) and a little javascript, not much and i have some jquery, and planning to add some more. But could you write a short example code..? Or do you know where i could find?

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

I dont have it fully setup at the moment but i have php (HTML) and a little javascript, not much and i have some jquery, and planning to add some more. But could you write a short example code..? Or do you know where i could find?

 

Sure, I can write up an example.

Link to comment
Share on other sites

Link to post
Share on other sites

Sure, I can write up an example.

Thanks alot :)

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks alot :)

<!DOCTYPE html><html><head><title>Hello World</title><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script type="text/javascript">/*  * Wrap javascript in an anonymous closure. This will limit the scope of any * functions or variables and ensure that the '$' shorthand does not collide * with any other libraries that we might be using. */(function ($, document, undefined) {/*  * Execute javascript using the jQuery shorthand for jQuery(document).ready(). * This will run the javascript when the DOM is ready. */$(function () {  /*   * Use jQuery.getJSON() to retrieve the data. Update the page HTML with   * values from the data.   */  $.getJSON("https://dweet.io/dweet/for/my-thing-name?hello=world", function (data) {    var $thing,        $created,        $hello;    $thing = $('#thing');    $created = $('#created');    $hello = $('#hello');        $thing.text(data.with.thing);    $created.text(data.with.created);    $hello.text(data.with.content.hello);  });});})(jQuery, this);</script></head><body><h1>Hello World</h1><p><strong>created:</strong> <span id="created"></span></p><h2>Thing</h2><p id="thing"></p><h2>Content</h2><h3>hello</h3><p id="hello"></p></body></html>
Link to comment
Share on other sites

Link to post
Share on other sites

Because they are separate. jQuery is written IN Javascript, but it is not part of the core Javascript that ships with browsers. You can write Javascript all day long without using jQuery.

*facepalm* no shit.

Link to comment
Share on other sites

Link to post
Share on other sites

<!DOCTYPE html><html><head><title>Hello World</title><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script type="text/javascript">/*  * Wrap javascript in an anonymous closure. This will limit the scope of any * functions or variables and ensure that the '$' shorthand does not collide * with any other libraries that we might be using. */(function ($, document, undefined) {/*  * Execute javascript using the jQuery shorthand for jQuery(document).ready(). * This will run the javascript when the DOM is ready. */$(function () {  /*   * Use jQuery.getJSON() to retrieve the data. Update the page HTML with   * values from the data.   */  $.getJSON("https://dweet.io/dweet/for/my-thing-name?hello=world", function (data) {    var $thing,        $created,        $hello;    $thing = $('#thing');    $created = $('#created');    $hello = $('#hello');        $thing.text(data.with.thing);    $created.text(data.with.created);    $hello.text(data.with.content.hello);  });});})(jQuery, this);</script></head><body><h1>Hello World</h1><p><strong>created:</strong> <span id="created"></span></p><h2>Thing</h2><p id="thing"></p><h2>Content</h2><h3>hello</h3><p id="hello"></p></body></html>

Thanks alot!

 

I only have one question more, what values/code do i have to change to get a dweet of my own like a temperature one? 

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

 

You change the first argument of getJSON(), which is your URL pointing to the JSON. Documentation: http://api.jquery.com/jquery.getjson/

Link to comment
Share on other sites

Link to post
Share on other sites

Hmm, i dont really gets it to work, sorry for beeing kind of a noob in javascript..

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

You change the first argument of getJSON(), which is your URL pointing to the JSON. Documentation: http://api.jquery.com/jquery.getjson/

 

I dont really get what i have to change, im kind of a noob. Could you explain a little deeper? 

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

I dont really get what i have to change, im kind of a noob. Could you explain a little deeper?

 

You call the getJSON method like so:

jQuery.getJSON('url', function (data) {  // do something with data});
Put the URL you need in place of 'url'. Quotes required.
Link to comment
Share on other sites

Link to post
Share on other sites

 

You call the getJSON method like so:

jQuery.getJSON('url', function (data) {  // do something with data});
Put the URL you need in place of 'url'. Quotes required.

 

Okey could you help me write it?, I've tried but haven't really succeded. 

 

I'm dweeting data to https://dweet.io/get/dweets/for/xQubeZ_temperature, and what my i get is this: {"thing":"xQubeZ_temperature","created":"2015-04-02T13:12:52.330Z","content":{"temperature":26,"humidity":33}}

 

So i need to get that content to get displayed, thats where i fail, I can't figure out how to get the temperature data, I only succeded with the date and that stuff.

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

Okey could you help me write it?, I've tried but haven't really succeded. 

 

I'm dweeting data to https://dweet.io/get/dweets/for/xQubeZ_temperature, and what my i get is this: {"thing":"xQubeZ_temperature","created":"2015-04-02T13:12:52.330Z","content":{"temperature":26,"humidity":33}}

 

So i need to get that content to get displayed, thats where i fail, I can't figure out how to get the temperature data, I only succeded with the date and that stuff.

Post your code.

Link to comment
Share on other sites

Link to post
Share on other sites

Post your code.

Its pretty much exactly the same as yours, but i found out it didnt work as i thought. The thing is your example made a dweet and posted it, but i just need to read it from a existing dweet and then display it. And thats where i fail beacuse i dont know so much on how javascript works so i can't really create a working code..

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

Its pretty much exactly the same as yours, but i found out it didnt work as i thought. The thing is your example made a dweet and posted it, but i just need to read it from a existing dweet and then display it. And thats where i fail beacuse i dont know so much on how javascript works so i can't really create a working code..

 

Just change the URL to get the latest dweet, or a list of all dweets and select the one you want based on some criteria. The remaining principles will be the same.

Link to comment
Share on other sites

Link to post
Share on other sites

Just change the URL to get the latest dweet, or a list of all dweets and select the one you want based on some criteria. The remaining principles will be the same.

Yeah i thought so so i tried, but i didnt get it to work.. Im probably doing something wrong but i dit know where

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

Yeah i thought so so i tried, but i didnt get it to work.. Im probably doing something wrong but i dit know where

 

If I can't see your code I can't help.

Link to comment
Share on other sites

Link to post
Share on other sites

If I can't see your code I can't help.

Yeah il post it as soon as i get on my pc (a bit later tonight)

FX-8350 GTX760 16GB RAM 250GB SSD + 1TB HDD

 

"How many roads must a man walk down?" "42"

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×