Shop OBEX P1 Docs P2 Docs Learn Events
Spinneret and SHT11 — Parallax Forums

Spinneret and SHT11

JAGOJAGO Posts: 49
edited 2011-10-26 07:24 in Accessories
Hi Friends,

I'm try to learn by my self about the spin programs and i have a spinneret web server with a SHT11 sensor, and a trying to show the temperatura and humidity in a web page but i have somo problems, because i don't have enought practice.

I work with the HTTPserver of Mike G. and work great...i follow the manual in http://spinneret.servebeer.com:5000/index.htm and i can read the RTC and show in the webpage also can control the led, but i don't know how insert the the object for read the SHT11 i have a sensirion demo from the Obex.

Anyone know something about?

Many thanks!
«1

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-10-05 14:45
    JAGO, it is not different than lighting an LED. Replace the LED method with a method that reads temperature and humidity.

    Do you have a SHT11 demo working? If not, do that first.
  • JAGOJAGO Posts: 49
    edited 2011-10-05 15:26
    Hi mike,

    many thanks for your answer, it's a honor for me stay in contact with you and apreciate so much your work.
    Well the sht11 demo works fine, i can see temperature and humidity in the PST.

    I understand how modify the methods, but a i have doubts with show the variables in the web page, i compare
    with the HTTPdate method because in here is the acces to the RTC and exist many transformations before send the data to the web page. May be send the temperature is more easy, i hope that.

    I try with your sugesti
  • Mike GMike G Posts: 2,702
    edited 2011-10-05 17:10
    Instead of sending the temperature and humidity to the Parallax Serial Terminal, save it in a memory. Then use the StringSend method to fire the response out the socket.
  • JAGOJAGO Posts: 49
    edited 2011-10-06 11:39
    Hi mike,

    I'm continue with my experiment and i try to send the sensor data to the web page but i can't, i don't know why...today insert the SHT object to the HTTPserver and compile ok... and i can send the data to the PST but when try with StringSend method the data not appears in the web page.

    PRI GetTemp
    sht.start(SHT_DATA, SHT_CLOCK) ' start sensirion object
    pause(200)
    sht.config(33,sht#off,sht#yes,sht#hires) 'configure SHT-11
    c := sht.getTemperatureC
    return c

    This is the method for take the temperature and works with the PST but when use the variable "c" in the StringSend(id, @c) not work...
    i don't know how do it...can you help me please?

    Thanks
  • Mike GMike G Posts: 2,702
    edited 2011-10-06 12:47
    Is "c" an integer? If so you must convert "c" to a string then send it. See the time example.

    There is no context around your code snippet. I have no idea what happened before or after PRI GetTemp. I would expect PRI GetTemp to save a temperature string in memory and return a pointer not invoke the StringSend method. StringSend should happen where the page is being rendered.

    Attach your code archive.
  • JAGOJAGO Posts: 49
    edited 2011-10-06 13:16
    Thanks mike,

    In fact now i trying to convert the c variable (integer) to string before send with the StringSend method. i attached all objects. i'm working with HTTPserver and i add the sensirion object for take the temperature and i create a GetTemp method for read the sensor and in the XmlTime method i'm trying to convert the "c" variable to string for send with the SendString method.

    Please if you can check will be great...

    Thanks
  • Mike GMike G Posts: 2,702
    edited 2011-10-06 18:48
    First off you're trying to start the SHT-11 each time the GetTemp method is called. The sht.Start method should be called once.

    This needs to be moved to the Initialize method of HTTPServer
      sht.start(SHT_DATA, SHT_CLOCK) ' start sensirion object
      pause(200)
      sht.config(33,sht#off,sht#yes,sht#hires) 'configure SHT-11
    

    Your service call should look something like the snippet below. I don't have the SHT-11 so I simulated the result.
    PRI GetTemp(id) 
      'c := sht.getTemperatureC
      c := 5
      dynamicContentPtr := @tempBuff
      
      BufferNum(c)
      PushDynamicContent(@xmlencode)
      PushDynamicContent(string("<root application='spinneret'><temp><![CDATA["))
      PushDynamicContent(@tempNum)
      PushDynamicContent(string("]]></temp></root>"))
    
      StringSend(id, @tempBuff) 
        
      bytefill(@tempBuff, 0, TEMP_BUFFER)
    
    PRI BufferNum(number) | offset     
      str.ToString(@number, @tempNum)
    
  • JAGOJAGO Posts: 49
    edited 2011-10-07 08:28
    Hi Mike,

    Many thanks for all, your code works fine! i insert your code in the xmltime method for try and when type the direction of my spinneret 192.168.1.8:5000/Xmltime apears the code showing the temperature:

    <root application="spinneret">
    <temp>
    <![CDATA[ 19 ]]>
    </temp>
    </root>

    the "19" is the temp of my sensor, great! but when open the web page time.htm (followeb the manual http://spinneret.servebeer.com:5000/services/xmltime.htm) and click the "Get Time" link but not appears the temperature...
    i don't modify the web page only modify the propeller code, will be necesary modify the web page too, or is other the problem??

    Many thanks for your help
  • Mike GMike G Posts: 2,702
    edited 2011-10-07 09:27
    The node < time > has changed to < temp >. Update the web page to grab the < temp > node or update the spin source to send < time > node.
  • JAGOJAGO Posts: 49
    edited 2011-10-07 10:14
    I understand and works!, i found the node and modify the spin source and when click in "GET TIME" link i see the temperature...great! now a trying to make other web page for only get temperature... in this moment i have a index.htm, led.htm, time.htm.

    <html>
    <head>
    <title>Get Temp</title>
    <script language="javascript" type="application/javascript">
    //Gets the browser specific XmlHttpRequest Object
    function getXmlHttpRequestObject() {
    if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
    alert("Your Browser does not support AJAX!\nIt's about time to upgrade don't you think?");
    }
    }

    //XmlHttpRequest object
    var req = getXmlHttpRequestObject();
    var htmlTarget;


    function getRequest(resource, elementId) {

    // handle the case where a querystring is not detected
    var char = "&";
    if(resource.indexOf("?", 0) == -1) {
    char = "?";
    }

    if (req.readyState == 4 || req.readyState == 0) {
    req.open("GET", resource + char + 'ms=' + new Date().GetTemp(), true);
    req.onreadystatechange = handleResponse;
    htmlTarget = elementId;
    req.send(null);
    return false;
    }
    }

    function handleResponse() {
    if (req.readyState == 4) {
    parseState(req.responseXML);
    }
    }

    function parseState(xDoc) {
    var target = document.getElementById(htmlTarget);
    target.innerHTML = xDoc.getElementsByTagName("temp")[0].childNodes[0].nodeValue;
    }

    </script>
    </head>
    <body style="background-color:beige;">
    <div style="width:600px;margin:auto;background-color:white;padding:10px;">
    <h1 style="text-align:center;color:blue;">SHT</h1>
    <div style="text-align:center;"><a href="index.htm">PRUEBA</a> | <a href="led.htm">LED</a> | <a href="time.htm">RTC </a> | <a href="temp.htm">SHT</a></div>
    <p>
    <a href="temp.htm" onClick="return getRequest('xmltemp', 'placeholder');">LEER TEMP</a>
    </p>
    <p><span id="placeholder"></span></p>
    </div>
    <script language='javascript' type='text/javascript'>
    getRequest('xmltemp', 'placeholder');
    </script>
    </body>
    </html>

    this is the code for the temp.htm (web page for read temperature) is the same time.htm but i change all time words for temp but a have a doubt with the red line, in theory i should see the temperature but don't work.

    may be, i'm wrong??

    Thanks so much for your help mike..
  • JAGOJAGO Posts: 49
    edited 2011-10-07 11:01
    Hi Mike,

    I DO IT! i have a new web page for read the temperature and works when i click the link "GET TEMP"..... thanks so much for your help. now my idea is implement a dinamic refresh for the web page for see the temp or the RTC data without clicking the link, do you know what is the best method for do it this?? or the system only works with the link??

    thanks mike.
  • Mike GMike G Posts: 2,702
    edited 2011-10-07 11:13
  • JAGOJAGO Posts: 49
    edited 2011-10-07 11:23
    Thanks mike,

    This is exactly for solve my problem, your code works great is very estable and fast....one more cuestion about the code, how many people can see the web page at the same time??

    Greetings
  • Mike GMike G Posts: 2,702
    edited 2011-10-07 12:55
    The W5100 (spinneret) can handle 4 concurrent requests. One request/response per socket. Please see the W5100 manual.
  • JAGOJAGO Posts: 49
    edited 2011-10-07 13:03
    Ok, understand in fact i'm checking the PDF of W5100. thanks for the info.
  • JAGOJAGO Posts: 49
    edited 2011-10-10 08:45
    Hi mike,

    this weekend i work very much with the spinneret...and work excellent, i add new pages and sensors and i can manipulate all variables, great. but i have a doubt about the acces over internet because in this moment only works via local red. so i read the document "make your spinneret internet accesible" and i understand about the port forward. but when i do in my router (d-link DIR-300) don't work and i can't access to my pink over internet only access over my local red.... so i need to know something new for access via internet to my spinneret?? or i need add or modify something in the code??

    i ask you because you do it and you are the expert... please if you have any idea please help me...

    Many thanks for all.
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-10-10 09:34
    JAGO wrote: »
    Hi mike,

    this weekend i work very much with the spinneret...and work excellent, i add new pages and sensors and i can manipulate all variables, great. but i have a doubt about the acces over internet because in this moment only works via local red. so i read the document "make your spinneret internet accesible" and i understand about the port forward. but when i do in my router (d-link DIR-300) don't work and i can't access to my pink over internet only access over my local red.... so i need to know something new for access via internet to my spinneret?? or i need add or modify something in the code??

    i ask you because you do it and you are the expert... please if you have any idea please help me...

    Many thanks for all.

    Your local "red"? That's "net" in English. I suspect your monolingual (English) readers might be confused by the term "red". [Or maybe I should give Parallax forum members more credit?]

    I'm following your thread eagerly, because I have the same questions. Interesting stuff.
  • JAGOJAGO Posts: 49
    edited 2011-10-10 09:39
    Hi,

    You have reason, in english is "Net". i from argentina and in my country the "net" is called "red".... thanks for follow.
  • LtechLtech Posts: 370
    edited 2011-10-10 11:25
    Interesting, do you plan to publish your code ?

    For internet don't use 80 they are often blocked by providers . Try 2011 .....

    Can you set your modem to DMZ (Demilitarized Zone) just for try.... you have to put your spinneret ip as destination.
    In DMZ your modem is transparent to the spinneret, no blocking, no firewall on your side ....
    If it's working you have to look in port forwarding.....
    Of course remove the DMZ mode after testing to protect your local network.
    In status of the modem you can look at wan ip. wan is the ip of your system for outsiders.
    By normal (cheap) accounts, wan is always changing !
  • Mike GMike G Posts: 2,702
    edited 2011-10-10 13:38
    @JAGO, You did not give us much to go on.

    What is your WAN IP? The IP assigned by your internet provider.
    What port is your Spinneret server on?
    What port are you forwarding?
    What URL are you using to hit the Spinneret?
    Did you remember the port in the URL?
  • JAGOJAGO Posts: 49
    edited 2011-10-10 14:28
    Mike,

    Thanks for reply... My WAN IP is dinamic so when i need try i found with http://www.whatismyip.com/ for example now my IP is 190.20.18.7.

    - my local IP asigned to my spinneret is 192.168.0.103
    - The port on my spinneret is 5000 (default in the spin code)
    - In my router configuration i forward to IP 192.168.0.103 and port 5000

    when i access to my spinneret via local net i type 192.168.0.103:5000 and works... i see the web pages and every goes well. but when i try to access via internet i type my WAN IP asigned by my internet provider, for example 190.20.18.7:5000 and don't work i can't see the web pages.

    I try to apply DMZ to my local IP but i have the same result, i can't see my spinneret....any idea?? i follow your manual step by step and i learn so much about the spinneret and i have your spinneret direction as reference http://spinneret.servebeer.com:5000/ for this reason i use the port 5000.

    please if you have any idea for solve my problem, i will be very grateful....thanks for all.
  • Mike GMike G Posts: 2,702
    edited 2011-10-10 15:45
    So you forwarded requests coming in on 190.20.18.7:5000 to 192.168.0.103:5000? You forwarded port 5000 traffic to 5000 right?

    I can ping 190.20.18.7 and tracert successfully it's something in your router configuration.

    When you look at your router setting you see 190.20.18.7 as the Internet IP address?
  • JAGOJAGO Posts: 49
    edited 2011-10-11 07:35
    Hi mike,

    Yes the requests coming in on my gobal IP are forwarded to my local IP.... i'm capturing the portforward page configuration and the firewall configuration when finish i'll upload for you can see. in my router setings appears the same IP address that i see in the page whatismyip.com.

    In few minutes i'll upload the screen captures of my router configuration, thanks for all.
  • JAGOJAGO Posts: 49
    edited 2011-10-11 08:54
    Hi mike,

    i have the captures of my router configuration, in the portforwarding page i need to type a "name" in my case i type "spinneret" and in the public port type 5000 in the IP address type the IP of my spinneret 192.168.0.103 and in the private port automatically indicate the same number of the public port. in the trafic i select "any", in this option i can select "TCP", "UDP", or "any".

    dir300port.jpg

    The firewall configuration appears automatically when i add the portforward rule and i can't modify anything only view.

    dir300fire.jpg

    I try to adding the IP of my spinneret to the DMZ but i have the same problem only see in my local red but when i try to access via internet typing my golbal ip i can't see my spinneret. What do you think about??

    Thanks for all mike.
  • JAGOJAGO Posts: 49
    edited 2011-10-21 09:48
    hi friends,

    well, i'm continuing with the work in my spinneret, i solve the problem with the internet access, i try with other router and make port forwarding and this time works, i can see my spinneret out side of my net.

    Now i'm experimenting with he micro SDcard i'm using a kingston 4GB and works great with the Datalogging section in the code of Mike G (HTTPserver) my doubt is, exist some methods for read the data in the TXT file created?? my idea is read the data from TXT archive and send to my web page for see the data, is posible do it??

    Thanks for your answers, greetings.
  • Mike GMike G Posts: 2,702
    edited 2011-10-21 18:02
    JAGO, that's how the web server works. A *.htm request comes in and the the page is rendered by the StaticFileHandler() method.
  • JAGOJAGO Posts: 49
    edited 2011-10-21 18:14
    Thanks mike,

    i'm trying to read the microsd card, do you have any example method for read the data in the txt archive with the spinneret?
    In this moment i can write data using the method for dataloggin in the HTTPserver, but i can't read the data, can you help me please?

    Thanks for all.
  • Mike GMike G Posts: 2,702
    edited 2011-10-21 18:49
    Let's say you saved a file name log.txt in the root directory on the SD card. Reading the file is as easy as http: // my.spinneret.url:port/log.txt
  • JAGOJAGO Posts: 49
    edited 2011-10-22 06:57
    Thanks mike,

    wow, is very easy. I thinked is more complicated, but not.

    The method for write data in the microsd is very cool and easy to use, about this... this method only can write in the same Log.txt
    is posible generate a new log.txt every day? Or only can write in the same log.txt every day?

    I'm trying to generate a new .txt in base to the filltime method, so doing this i'll have a new log.txt every day and the data will not blend.

    Do you think that is posible?

    Greetings
  • Mike GMike G Posts: 2,702
    edited 2011-10-22 07:24
    Sure, just get and format the date as a string; YYMMDD. Then append the date to the the file name. ie. log111022.txt. In the Append log method, check if the file already exists if the file does not exist create the file otherwise append to the file. The logic to format a date, create a file, and check if a file exists can be found in the HTTPServer code base. The AppendLog method already has the logic to create a new log if the file does not exist. All you have to do is build the file name and supply the data.
Sign In or Register to comment.