Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Put the analog Value into webserver

analog input webserver

  • Please log in to reply
1 reply to this topic

#1 Irma Nirmalasari

Irma Nirmalasari

    New Member

  • Members
  • Pip
  • 1 posts

Posted 03 September 2013 - 07:42 AM

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. :P

 

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        }    }}


#2 SteveAndrews

SteveAndrews

    Member

  • Members
  • PipPip
  • 17 posts
  • LocationOrange County, CA

Posted 27 September 2013 - 09:35 AM

That's a pretty neat project! What is the full error? What line is the error occurring on?







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.