Hi everyone..
i am a student from Indonesia, and i have a final project about counting kWh with netduino plus.
before that, i am sorry for my bad english.
in my project, i want to put my analog value in to webserver and i can request from my browser.
so i can see how much energy that i used.
after read a lot of post and complate with my code,
There's an error that my value cant read in current context.
i need your help..
this is my code..
using System;using System.Threading;using Microsoft.SPOT;using System.Net;using System.Net.Sockets;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using Microsoft.SPOT.Net;using System.IO;namespace NetduinoPlusWebServer{ public class Program { const string WebFolder = "SDWeb"; private const int MaximumValue = 1023; private const float AnalogReference = 3.3f; private static StreamWriter sw; static AnalogInput voltage; public static void Main() { Listener webServer = new Listener(RequestReceived); } private static void RequestReceived(Request request) { const double maxVoltage = 3.3; const int maxAdcValue = 1023; // 10-bit Resolution (ADC) var voltagePort = new AnalogInput(Pins.GPIO_PIN_A2); var currentPort = new AnalogInput(Pins.GPIO_PIN_A0); sw = new StreamWriter(@"SDfile.csv");//sdcardfilename OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); while (true) { //Part Sensor VOLTAGE int rawValue = voltagePort.Read(); double value = rawValue + 114.11; double volt = value / 2.15; //Part Sensor CURRENT int currentvalue = currentPort.Read(); double varus = (currentvalue* maxVoltage) / maxAdcValue; double icount = currentvalue - 312; double current = icount / 57.62; //Part KWatt double voltage = volt; double iconv = current * 1000; //convert to miliampere double kWh = voltage * iconv / 3600; Debug.Print("Total kWh= " + kWh.ToString()); sw.Write(kWh.ToString()); sw.Write("n"); sw.Flush(); sw.Close(); led.Write(!led.Read());// Blink LED to show we're still responsive Thread.Sleep(500); } request.SendResponse( "<html>" + "<header> Analisis Perhitungan Jumlah Daya Pada Kamar Kos</header>" + "<p> Time (relative to start time): " + DateTime.Now.ToString() + "</p>" + "<p> Jumlah kWh Anda sebesar: " + kWh + "</p>" + "</body>" + "</html>" ); // Use this for a really basic check that it's working //request.SendResponse("<html><body><p>Request from " + request.Client.ToString() + " received at " + DateTime.Now.ToString() + "</p><p>Method: " + request.Method + "<br />URL: " + request.URL +"</p></body></html>"); // Send a file } }}