Web_AjaxRGB_mobile issue

102 views
Skip to first unread message

Konsarna

unread,
Oct 28, 2013, 5:32:29 AM10/28/13
to webd...@googlegroups.com
hello,
I have a problem with the sketch Web_AjaxRGB_mobile.I have added some commands in order to show some temperarure measurements and after a certain value it appears the buttons.My problem is that I have added a refresh line (because I want to keep the new temperature measurements) but the button is refreshed too and cannot keep the previous value as a result I have put on the button the led is on but after the refresh the slider is off although the led is on. Do you think I should work with databases so that I can keep the previous state of the button or a variable ,or use AJAX and separate the page so it is only refreshed regarding the sensor?
thak you

Ben Combee

unread,
Oct 28, 2013, 11:11:11 AM10/28/13
to webduino
You should only need to make an AJAX call back to the server to get the new temp value, and then just update that part of the page via JavaScript.  Since jQuery is loaded, it could be as simple as having the JavaScript code get the element with the temp value by ID then change the content.


--
You received this message because you are subscribed to the Google Groups "Webduino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webduino+u...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webduino.
For more options, visit https://groups.google.com/groups/opt_out.

Konsarna

unread,
Nov 5, 2013, 4:40:20 PM11/5/13
to webd...@googlegroups.com
I am trying to include the call back function of AJAX in the head of html after the :

if (type == WebServer::GET)
  {
    P(message) = 
"<!DOCTYPE html><html><head>".........
.......
"<script>";
function loadXMLDoc();
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
 
but I am getting errors like:
 'function' was not declared in this scope,
'loadXMLDoc' was not declared in this scope,
'window' was not declared in this scope etc 
haven't I understand well the call back for AJAX will be written in that part or not?
thanks in advance

Ben Combee

unread,
Nov 5, 2013, 4:57:53 PM11/5/13
to webduino
it sounds like you're trying to include the JS code in the Arduino app rather than in the streing that's printed to the web browser.

Konsarna

unread,
Nov 5, 2013, 5:05:41 PM11/5/13
to webd...@googlegroups.com
I thought that it is essential to put that (script)in the head part of html and in the body part the div id=tempC that I would use to make the resposne from server back to the browser.You suggest me to include all the ajax call back function in the body close to where the value of tempC is displayed?
thank you for your instance response

Konsarna

unread,
Nov 5, 2013, 7:46:09 PM11/5/13
to webd...@googlegroups.com

Konsarna

unread,
Nov 5, 2013, 7:52:40 PM11/5/13
to webd...@googlegroups.com
I think I am fixing it by using "", but in the field that I am using the

document.getElementById("myDiv")

the myDiv will be the the string showing the measurement of tempC right?can that happen although tempC is a variable?

Ben Combee

unread,
Nov 6, 2013, 11:45:54 AM11/6/13
to webduino
There's a fundamental idea that I feel you're missing... you're sending multiple things from the Arduino.  The first is a web page that has no data, just HTML code and JavaScript to run in the browser.  This doesn't need to have any temperature data in it.  The second is the AJAX call that the JavaScript code makes back to the Ardunio.  This returns just a simple value, that gets used by the JS code you already sent to update the page.

In my original example, I used jQuery as a library to simplify the JavaScript code.  The HTML page that the Arduino sent included a reference to pull jQuery from a common external website.  But you have to realize that your writing code for two different systems -- one runs on the Arduino, one in the browser.

Konsarna

unread,
Nov 6, 2013, 5:06:02 PM11/6/13
to webd...@googlegroups.com
ok thanks for the explanation. I suppose you are telling the difference because it is wrong what I wrote before about using the ""' in the AJAX.Could you tell me where is the right place to put the call back function of ajax because wherever I put it I get errors like var or function is not declared etc...
I am using something like that for the call back function isn' it right?of course with some changes 

<script>
var xmlhttp;
function loadXMLDoc(url,cfunc)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function myFunction()
{
loadXMLDoc("ajax_info.txt",function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  });

 should I include sth in the beggining for the ajax like jquery there is nothing like that around ,is it wrong the way I am using the call back function?

Konsarna

unread,
Nov 6, 2013, 6:04:38 PM11/6/13
to webd...@googlegroups.com
I think that the right place is under the last server.print that concerns the display of temp and of course without any """ (I have put an id to a section that I want to be renewed by ajax e.g.id=myDiv )but i am getting errors like var was not declared in this scope ,request was not declared in this scope,function was not declared in this scope etc it seems it is all wrong.Am I mistaken the way I am using call back function is it possible to send a link or a small tutorial of how my function will be...

Konsarna

unread,
Nov 18, 2013, 6:02:00 AM11/18/13
to webd...@googlegroups.com
Hi again,
after some weeks I did it,I had to study a bit more the examples to do what you have suggested me since I am not very keen on these issues but day after day I learn a lot and that is really nice thanks anyway for your instant resposnes and directions!I would like to ask sth else now I have mixed the web_ajax_rgb mobile so that now I have measurements of 3,4 sensors displayed and under them buttons with yor advice I have made ajax call backs fot the sensor measurements and erased the whole refresh of the page so now I can see both the sensor refreshed and the button on the previous value.I have some simple questions how can I display the sensor measuremnet in the same line where I am writing "the temperature is:" due to the multiple P(macros) i am using the value is diplayed under that line like:

"the temperature is:" 
17.25

and the code is like that
"<li>the temperature is  : "
"<div id=\"temp\">";  
server.printP(message);
sensors.requestTemperatures();
printTemperature(insideThermometer);
float tempC = sensors.getTempC(insideThermometer);
server.print (tempC);
 I want it to be all together can that happen or due to the multiple serverprint P it is impossible?
another query is if I want the buttons to appear only after a significal value and not during all the time can I make it? because now I have disabled the refresh line and my page is refreshed in parts with ajax and only the values of the sensors?or display a warning icon when the temp for example has increased a lot
thank you

Konsarna

unread,
Nov 22, 2013, 4:07:28 PM11/22/13
to webd...@googlegroups.com
hi can you give me a clue of how can I make a button after a certain value to be off without the interaction of the user  for example from 30 degrees on I want to make it show off and keep it there

Ben Combee

unread,
Nov 22, 2013, 4:20:28 PM11/22/13
to webduino
Look at the setTimeout and setInterval functions in JavaScript -- these let the code running in your webpage set actions to be run in the future, such as making a new query to the device to update a control.

Konsarna

unread,
Nov 22, 2013, 4:36:54 PM11/22/13
to webd...@googlegroups.com
thanks a lot!can i make another question I want to extend a bit more the example web_ajax_rgb mobile: like connecting something that can detect whether the device or little led in the example is actually on or off that can be made with a sensor measuring current lets say and then I will display a small icon near the on off slider to assure that it is on. My query is since I dont have sth like that(sensor measuring current) is there any other way I can make it using a battery at the same pin as led and if I can read the value of battery then the led means it is on otherwise it is off and with the tag <img> i will display an icon . how does it sounds?
thanks a lot

Ben Combee

unread,
Nov 22, 2013, 4:39:17 PM11/22/13
to webduino
These questions are better asked on the Arduino forums: see http://forum.arduino.cc/

Vaggelis Spinthakis

unread,
Dec 30, 2013, 6:09:45 PM12/30/13
to webd...@googlegroups.com
Hi i am trying to make an automation with the arduino based on the webduino Ajaxrgb demo.Currently I have manage to import another button in the demo,button when I tried to import 2 more there is no feedback,on the buttons.I have made corretly the changes in the code of post and get methods,but is not working.also can some one advice me how can import an analogsensor reading(tempsensor).thank you.
And a happy new year.

Ben Combee

unread,
Jan 1, 2014, 10:23:06 AM1/1/14
to webduino
In this situation, it's very possible that your additional buttons are
stomping on one of the I/O lines used to communicate to the Ethernet
shield. What allocation have you made here?

Vaggelis Spinthakis

unread,
Jan 1, 2014, 4:56:49 PM1/1/14
to webd...@googlegroups.com
No this is not the situation,i have use digital pin 3,5,6,7,8,9.No one of this is used on the ethernet shield.In the board i  can see the Receive led flushing while the transmit is not working even if i interact with the sliders.So will it be a coding error?Maybe in the post method?

Ben Combee

unread,
Jan 3, 2014, 6:13:38 PM1/3/14
to webduino
It could be how those additional buttons or sliders are hooked up.
I'd try to debug the web application from the browser side. If you're
using Chrome, you can open the developer tools and use the network tab
to watch the AJAX POST calls back to the Webduino. Maybe you've done
something to overload the Ethernet stack in the Wiznet chip.

Unfortunately, there's no enough information here to give an exact diagnosis.

On Wed, Jan 1, 2014 at 3:56 PM, Vaggelis Spinthakis

Vaggelis Spinthakis

unread,
Jan 5, 2014, 6:55:42 PM1/5/14
to webd...@googlegroups.com
i found the problem,it was in the   $(document).ready(function  i rewrote the line and it works.Thank you very much for the debug tip.
Now i want to add a temperature display  in the sketch,but i am confused how to do that.Do i have to use Dallas Temp,or an Lm3x sensor will do the job?I cant find any example on the net implementing temperature sensor with webduino library...

Ben Combee

unread,
Jan 7, 2014, 6:23:55 PM1/7/14
to webduino
I've had good luck with the LM35DZ sensor -- see
http://www.futurlec.com/Linear/LM35DZ.shtml for the data sheet. It
just connects to an analog input pin and outputs the temperature as a
voltage that the ADC will convert to a value for your app's use.

On Sun, Jan 5, 2014 at 5:55 PM, Vaggelis Spinthakis
Reply all
Reply to author
Forward
0 new messages