I am new here.
I would like to know how to read a temperature from the web.
This is my program to read the temperature and it s working well:
using System; using System.Net; using System.Net.Sockets; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace i2c_bus_temp { public class Program { public static void Main() { byte[] buffer_read = new byte[2]; byte[] buffer_write = new byte[1]; I2CDevice.Configuration config = new I2CDevice.Configuration(0x48, 100); // naslov naprave v hexa,binarno je1001000, zadnji trije določajo A2 A1 A0. I2CDevice RTC = new I2CDevice(config); buffer_write[0] = 0x00; I2CDevice.I2CReadTransaction tran_read = I2CDevice.CreateReadTransaction(buffer_read); I2CDevice.I2CWriteTransaction tran_write = I2CDevice.CreateWriteTransaction(buffer_write); while (true) { I2CDevice.I2CTransaction[] tran = new I2CDevice.I2CTransaction[] { tran_write }; int data = RTC.Execute(tran, 100); Debug.Print("\nThe number of data transfered is: " + data.ToString()); tran = new I2CDevice.I2CTransaction[] { tran_read }; data = RTC.Execute(tran, 100); int tempH; int tempL; tempH = buffer_read[0]*8; tempL = buffer_read[1]/32; Debug.Print("\nThe number of data transfered is: " + (tempH+tempL)/8.0 +" °C"); Thread.Sleep(1000); } } } }
I will be hapy if someone could connect my temperature to the web with using this program:
using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; using Blinq.Netduino.Web; namespace ServerExample { /// <summary> /// Example for using the Blinq.Netduino.Webserver class /// </summary> public class Program { static InputPort bb = new InputPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled); static WebServer server = new WebServer(80); public static void Main() { bool buttonState = false; server.CommandReceived += new WebServer.CommandReceivedHandler(server_CommandReceived); server.AllowedCommands.Add(new WebCommand("button", 0)); server.Start(); } private static void server_CommandReceived(object source, WebCommandEventArgs e) { Debug.Print("Command received:" + e.Command.CommandString); switch (e.Command.CommandString) { case "button": { e.ReturnString = "<html><body><p>Butoon je v stanju: " + !bb.Read() + "</p></body></hmtl>"; break; } } } } }
Thanks in advance:)
Edited by Stefan, 19 July 2011 - 02:59 PM.
Added [code] tags