ds18

Arduino specifieke Software
Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

ds18

Berichtdoor weske2000 » 24 Jan 2015, 21:21

Goede avond

Ik ben bezig met de onderstaande code

Alleen loop tegen 2 probleempjes aan

Er is maar 1 sensor ik wil er graag 5
En als ik de temp via het web uitlees staat er geen naam bij .
Kan iemand me hier alsjeblieft mee helpen .?

Alvast vriendelijk dank

----------------------------------------------------------------------------------

/*
Arduino Web Server Temperature Sensor
=====================================

A web server that will read the values of a 1-Wire temperature sensor and output
XML with temperature in Celcius and Fahrenheit.

- Adapted by Gordon Turner from code by David A. Mellis and Tom Igoe.

- Ethernet shield attached to pins 10, 11, 12, 13
- 1-Wire temperature sensor attached to digital pin 3.

- Requires 1-wire Ardunio Library and Dallas Temperature Control Arduino Library.
- Included in Libraries folder or online:
http://www.pjrc.com/teensy/arduino_libr ... neWire.zip
http://milesburton.com/Dallas_Temperatu ... ary#Latest

- Sample output XML:

<?xml version=\"1.0\"?>
<xml>
<temperature>
<celcius>0</celcius>
<fahrenheit>32</fahrenheit>
</temperature>
</xml>

- Sample output XML with error:

<?xml version=\"1.0\"?>
<xml>
<temperature>
ERROR
</temperature>
</xml>

*/

#include <SPI.h>
#include <Ethernet.h>

#include <OneWire.h>
#include <DallasTemperature.h>


// 1-Wire data wire is attached to ditigal pin 3.
#define ONE_WIRE_BUS 3

// Intialize an 1-Wire instance.
OneWire oneWire(ONE_WIRE_BUS);

// Pass 1-Wire reference to Dallas Temperature library.
DallasTemperature sensors(&oneWire);

// 1-Wire sensor address, use OneWireAddressFinder to find.
DeviceAddress outsideThermometer = { 0x28, 0x85, 0x95, 0x3A, 0x04, 0x00, 0x00, 0xB7 };

// Ethernet Shield MAC address, use value on back of shield.
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x10, 0x5A };

// IP address, will depend on your local network.
IPAddress ip(192,168,2,70);

// Initialize the Ethernet server library, use port 80 for HTTP.
EthernetServer server(80);

// String for reading from client
String request = String(100);
String parsedRequest = "";



// NOTE: Serial debugging code has been disabled.

void setup()
{
// Open Serial communications and wait for port to open.
Serial.begin(9600);

// Start the sensor library.
sensors.begin();

if( !sensors.isConnected(outsideThermometer) )
{
Serial.println("Error, no sensors found.");
}
else
{
Serial.println("Found sensor, setting up.");
}

// Set the resolution to 10 bit.
sensors.setResolution(outsideThermometer, 10);

Serial.println("Setting up Ethernet");

// Start the Ethernet connection and the server.
Ethernet.begin(mac, ip);
server.begin();

Serial.print("Server is at ");
Serial.println(Ethernet.localIP());
}


void loop()
{
// Listen for incoming clients.
EthernetClient client = server.available();

if (client)
{
Serial.println("Client connected");

// An http request ends with a blank line.
boolean currentLineIsBlank = true;

while (client.connected())
{
if (client.available())
{
char c = client.read();

// Read http request.
if (request.length() < 100)
{
request += c;
}

// If you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply.
if (c == '\n' && currentLineIsBlank)
{
Serial.println("Finished reading request.");
Serial.println("http request: '" + request + "'");

// Response looks like:
// GET /?format=JSONP HTTP/1.1
// Host: 192.168.2.70
// User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X

if (request.startsWith("GET /?format="))
{
parsedRequest = request.substring(request.indexOf('format=')+1, request.indexOf("HTTP")-1);
Serial.println("Parsed request: '" + parsedRequest + "'");
}



Serial.println("Reading sensor.");

float celsius;
float fahrenheit;
String error = "";

if( sensors.isConnected(outsideThermometer) )
{
sensors.requestTemperatures();
celsius = sensors.getTempC(outsideThermometer);
fahrenheit = sensors.getTempF(outsideThermometer);

Serial.print("C: ");
Serial.println(celsius);
Serial.print("F: ");
Serial.println(fahrenheit);
}
else
{
error = "Error reading sensors";
Serial.println(error);
}


if( parsedRequest == "XML" )
{
sendXmlResponse(client, celsius, fahrenheit, error);
}
else if(parsedRequest.startsWith("JSONP"))
{
// Parse callback arguement.
String callback = parsedRequest.substring(parsedRequest.indexOf('callback=')+1, parsedRequest.length());
callback = callback.substring(0, callback.indexOf('&'));

Serial.println("Using callback: " + callback);

sendJsonpResponse(client, celsius, fahrenheit, error, callback);
}
else
{
// Default to JSON.
sendJsonResponse(client, celsius, fahrenheit, error);
}


break;
}

if (c == '\n')
{
// Character is a new line.
currentLineIsBlank = true;
}
else if (c != '\r')
{
// Character is not a new line or a carriage return.
currentLineIsBlank = false;
}

}

}

// Give the web browser time to receive the data.
delay(1);

// Close the connection:
client.stop();

Serial.println("Client disonnected");
}

// Reset the request.
request = "";
parsedRequest = "";
}


/*
*
*/
void sendXmlResponse(EthernetClient client, float celsius, float fahrenheit, String error)
{
if(error == "")
{
Serial.println("Sending XML response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/xml");
client.println("Connnection: close");
client.println();

// Send XML body.
client.println("<?xml version=\"1.0\"?>");
client.println("<xml>");
client.print("<temperature>");
client.print("<celcius>");
client.print(celsius);
client.print("</celcius>");
client.print("<fahrenheit>");
client.print(fahrenheit);
client.print("</fahrenheit>");
client.println("</temperature>");
client.println("</xml>");
}
else
{
Serial.println("Sending XML error response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/xml");
client.println("Connnection: close");
client.println();

// Send XML body.
client.println("<?xml version=\"1.0\"?>");
client.println("<xml>");
client.print("<temperature>");
client.print(error);
client.println("</temperature>");
client.println("</xml>");
}
}


/*
*
*/
void sendJsonpResponse(EthernetClient client, float celsius, float fahrenheit, String error, String callback)
{

if(error == "")
{
Serial.println("Sending JSONP response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connnection: close");
client.println();

// Send JSONP body.
client.println(callback + "({");
client.println(" \"temperature\": {");
client.print(" \"celcius\": ");
client.print(celsius);
client.println(",");
client.print(" \"fahrenheit\": ");
client.println(fahrenheit);
client.println(" }");
client.println("});");
}
else
{
Serial.println("Sending JSONP error response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connnection: close");
client.println();

// Send JSONP body.
client.println(callback + "({");
client.println(" \"error\": \"" + error + "\"");
client.println("})");
}
}


/*
*
*/
void sendJsonResponse(EthernetClient client, float celsius, float fahrenheit, String error)
{
if(error == "")
{
Serial.println("Sending JSON response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connnection: close");
client.println();

// Send JSON body.
client.println("{");
client.println(" \"temperature\": {");
client.print(" \"celcius\": ");
client.print(celsius);
client.println(",");
client.print(" \"fahrenheit\": ");
client.println(fahrenheit);
client.println(" }");
client.println("}");
}
else
{
Serial.println("Sending JSON error response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connnection: close");
client.println();

// Send JSON body.
client.println("{");
client.println(" \"error\": \"" + error + "\"");
client.println("}");
}
}

Advertisement

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: ds18

Berichtdoor nicoverduin » 24 Jan 2015, 22:36

Eerst maar eens leesbaarder maken:
cpp code
/*
Arduino Web Server Temperature Sensor
=====================================

A web server that will read the values of a 1-Wire temperature sensor and output
XML with temperature in Celcius and Fahrenheit.

- Adapted by Gordon Turner from code by David A. Mellis and Tom Igoe.

- Ethernet shield attached to pins 10, 11, 12, 13
- 1-Wire temperature sensor attached to digital pin 3.

- Requires 1-wire Ardunio Library and Dallas Temperature Control Arduino Library.
- Included in Libraries folder or online:
http://www.pjrc.com/teensy/arduino_libr ... neWire.zip
http://milesburton.com/Dallas_Temperatu ... ary#Latest

- Sample output XML:

<?xml version=\"1.0\"?>
<xml>
<temperature>
<celcius>0</celcius>
<fahrenheit>32</fahrenheit>
</temperature>
</xml>

- Sample output XML with error:

<?xml version=\"1.0\"?>
<xml>
<temperature>
ERROR
</temperature>
</xml>

*/

#include <SPI.h>
#include <Ethernet.h>

#include <OneWire.h>
#include <DallasTemperature.h>

// 1-Wire data wire is attached to ditigal pin 3.
#define ONE_WIRE_BUS 3

// Intialize an 1-Wire instance.
OneWire oneWire(ONE_WIRE_BUS);

// Pass 1-Wire reference to Dallas Temperature library.
DallasTemperature sensors(&oneWire);

// 1-Wire sensor address, use OneWireAddressFinder to find.
DeviceAddress outsideThermometer = { 0x28, 0x85, 0x95, 0x3A, 0x04, 0x00, 0x00,
0xB7 };

// Ethernet Shield MAC address, use value on back of shield.
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x10, 0x5A };

// IP address, will depend on your local network.
IPAddress ip(192, 168, 2, 70);

// Initialize the Ethernet server library, use port 80 for HTTP.
EthernetServer server(80);

// String for reading from client
String request = String(100);
String parsedRequest = "";

// NOTE: Serial debugging code has been disabled.

void setup() {
// Open Serial communications and wait for port to open.
Serial.begin(9600);

// Start the sensor library.
sensors.begin();

if (!sensors.isConnected(outsideThermometer)) {
Serial.println("Error, no sensors found.");
} else {
Serial.println("Found sensor, setting up.");
}

// Set the resolution to 10 bit.
sensors.setResolution(outsideThermometer, 10);

Serial.println("Setting up Ethernet");

// Start the Ethernet connection and the server.
Ethernet.begin(mac, ip);
server.begin();

Serial.print("Server is at ");
Serial.println(Ethernet.localIP());
}

void loop() {
// Listen for incoming clients.
EthernetClient client = server.available();

if (client) {
Serial.println("Client connected");

// An http request ends with a blank line.
boolean currentLineIsBlank = true;

while (client.connected()) {
if (client.available()) {
char c = client.read();

// Read http request.
if (request.length() < 100) {
request += c;
}

// If you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply.
if (c == '\n' && currentLineIsBlank) {
Serial.println("Finished reading request.");
Serial.println("http request: '" + request + "'");

// Response looks like:
// GET /?format=JSONP HTTP/1.1
// Host: 192.168.2.70
// User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X

if (request.startsWith("GET /?format=")) {
parsedRequest =
request.substring(
request.indexOf(
'format=')+1, request.indexOf("HTTP")-1)
;
Serial.println(
"Parsed request: '" + parsedRequest + "'");
}

Serial.println("Reading sensor.");

float celsius;
float fahrenheit;
String error = "";

if (sensors.isConnected(outsideThermometer)) {
sensors.requestTemperatures();
celsius = sensors.getTempC(outsideThermometer);
fahrenheit = sensors.getTempF(outsideThermometer);

Serial.print("C: ");
Serial.println(celsius);
Serial.print("F: ");
Serial.println(fahrenheit);
} else {
error = "Error reading sensors";
Serial.println(error);
}

if (parsedRequest == "XML") {
sendXmlResponse(client, celsius, fahrenheit, error);
} else if (parsedRequest.startsWith("JSONP")) {
// Parse callback arguement.
String callback = parsedRequest.substring(
parsedRequest.indexOf(
'callback=')+1, parsedRequest.length())
;
callback = callback.substring(0, callback.indexOf('&'));

Serial.println("Using callback: " + callback);

sendJsonpResponse(client, celsius, fahrenheit, error,
callback);
} else {
// Default to JSON.
sendJsonResponse(client, celsius, fahrenheit, error);
}

break;
}

if (c == '\n') {
// Character is a new line.
currentLineIsBlank = true;
} else if (c != '\r') {
// Character is not a new line or a carriage return.
currentLineIsBlank = false;
}

}

}

// Give the web browser time to receive the data.
delay(1);

// Close the connection:
client.stop();

Serial.println("Client disonnected");
}

// Reset the request.
request = "";
parsedRequest = "";
}

/*
*
*/
void sendXmlResponse(EthernetClient client, float celsius, float fahrenheit,
String error) {
if (error == "") {
Serial.println("Sending XML response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/xml");
client.println("Connnection: close");
client.println();

// Send XML body.
client.println("<?xml version=\"1.0\"?>");
client.println("<xml>");
client.print("<temperature>");
client.print("<celcius>");
client.print(celsius);
client.print("</celcius>");
client.print("<fahrenheit>");
client.print(fahrenheit);
client.print("</fahrenheit>");
client.println("</temperature>");
client.println("</xml>");
} else {
Serial.println("Sending XML error response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/xml");
client.println("Connnection: close");
client.println();

// Send XML body.
client.println("<?xml version=\"1.0\"?>");
client.println("<xml>");
client.print("<temperature>");
client.print(error);
client.println("</temperature>");
client.println("</xml>");
}
}

/*
*
*/
void sendJsonpResponse(EthernetClient client, float celsius, float fahrenheit,
String error, String callback) {

if (error == "") {
Serial.println("Sending JSONP response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connnection: close");
client.println();

// Send JSONP body.
client.println(callback + "({");
client.println(" \"temperature\": {");
client.print(" \"celcius\": ");
client.print(celsius);
client.println(",");
client.print(" \"fahrenheit\": ");
client.println(fahrenheit);
client.println(" }");
client.println("});");
} else {
Serial.println("Sending JSONP error response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connnection: close");
client.println();

// Send JSONP body.
client.println(callback + "({");
client.println(" \"error\": \"" + error + "\"");
client.println("})");
}
}

/*
*
*/
void sendJsonResponse(EthernetClient client, float celsius, float fahrenheit,
String error) {
if (error == "") {
Serial.println("Sending JSON response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connnection: close");
client.println();

// Send JSON body.
client.println("{");
client.println(" \"temperature\": {");
client.print(" \"celcius\": ");
client.print(celsius);
client.println(",");
client.print(" \"fahrenheit\": ");
client.println(fahrenheit);
client.println(" }");
client.println("}");
} else {
Serial.println("Sending JSON error response.");

// Send a standard http response header.
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: application/json");
client.println("Connnection: close");
client.println();

// Send JSON body.
client.println("{");
client.println(" \"error\": \"" + error + "\"");
client.println("}");
}
}
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: ds18

Berichtdoor nicoverduin » 24 Jan 2015, 22:45

Heb je al een geprobeerd om de clint.print ff te testen met Serial.print? Maw weet je wel of die responses er wel goed uit zien?
Je kan meerdere sensoren parallel zetten (ff googelen op "multiple Ds18B20 arduino".
Wel was er laatst iemand die aangaf dat hij problemen met meervoudige sensors op 1-wire. Maar in de software heb je nog niets opgelost daarvoor toch?
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

Re: ds18

Berichtdoor weske2000 » 25 Jan 2015, 13:18

Heb een perfect werkende code.
Alleen is deze alleen via de serial monitor uit te lezen.
Ik gebruik 5 sensoren heb de id,s uitgezocht en de juiste benaming gegeven.
Alleen is deze niet voor online gebruik.

Mvg wesley

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: ds18

Berichtdoor nicoverduin » 25 Jan 2015, 14:54

Heb je nu nog een vraag? Want uit deze cryptische omschrijving heb ik geen idee meer wat je wilt?
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

Re: ds18

Berichtdoor weske2000 » 25 Jan 2015, 15:51

De onderstaande code is goed werkend alleen is dit makkelijk online te maken ?



/* Colani.nl Meerdere DS18B20 Temperatuur Sensors op 1 draad (1wire)
Verbindingen:
DS18B20 Pinnen (van links naar rechts, pinnen naar beneden, platte kant naar boven)
- Links = GND
- Midden = Signaal (Pin 3): (met een 3.3K aan +3 Volt of een 4.7K weerstand aan +5 Volt)
- Rechts = +5 or +3.3 Volt

Vragen: arduino@colani.nl
Gebaseerd op een voorbeeld van Rik Kretzinger

/*-----( Importeer benodigde libraries )-----*/
// Download 1-wire Library hier: http://colani.nl/arduino/category/libraries/
#include <OneWire.h>

// Download DallasTemperature Librarie hier: http://colani.nl/arduino/category/libraries/
#include <DallasTemperature.h>

/*-----( Verklaar Constanten en Pin Nummers )-----*/
#define ONE_WIRE_BUS_PIN 3

/*-----( Verklaar objecten )-----*/
// Setup een oneWire voorbeeld om te communiceren met OneWire sensoren
OneWire oneWire(ONE_WIRE_BUS_PIN);

// Geef de oneWire gegevens door aan Dallas Temperature.
DallasTemperature sensors(&oneWire);

/*-----( Verklaar Variablelen )-----*/
// Geef de addressen op van je 1-Wire temperatuur sensors.
// Gebruik deze sketch om de adressen van je sensors te achterhalen.
// http://colani.nl/arduino/wp-content/upl ... ressen.ino
// Ik heb er hier 5 in gebruik, maar deze lijst kun je naar behoefte aanpassen.

DeviceAddress Probe01 = { 0x28, 0x88, 0x27, 0x0A, 0x05, 0x00, 0x00, 0xD2 };
DeviceAddress Probe02 = { 0x28, 0x58, 0x21, 0x0A, 0x05, 0x00, 0x00, 0x8A };
DeviceAddress Probe03 = { 0x28, 0x45, 0x1D, 0x0A, 0x05, 0x00, 0x00, 0x3E };
DeviceAddress Probe04 = { 0x28, 0xF7, 0x28, 0x0A, 0x05, 0x00, 0x00, 0x01 };
DeviceAddress Probe05 = { 0x28, 0x7F, 0x32, 0x0A, 0x05, 0x00, 0x00, 0x8B };


void setup() /****** SETUP: Een keer ******/
{
// starten van seriele poort om resultaten te tonen
Serial.begin(9600);
Serial.print("Initialiseren Temperatuur Control Library Versie ");
Serial.println(DALLASTEMPLIBVERSION);

// Initializeren temperatuur meet librarie
sensors.begin();

// Stel de resloutie in op 10 bit
// Dit kan van 9 tot 12 bits .. lager is sneller
sensors.setResolution(Probe01, 10);
sensors.setResolution(Probe02, 10);
sensors.setResolution(Probe03, 10);
sensors.setResolution(Probe04, 10);
sensors.setResolution(Probe05, 10);

}//--(Einde setup )---

void loop() /****** LOOP: loopt voor eeuwig ******/
{
delay(8000);
Serial.println();
Serial.print("Aantal sensoren gevonden op pin / bus 2 = ");
Serial.println(sensors.getDeviceCount());
Serial.print("Opvragen temperatuur... ");
Serial.println();

// Temperatuur opvragen alle sensoren op bus 2
sensors.requestTemperatures();

Serial.print("GANG temperatuur is: ");
printTemperature(Probe01);
Serial.println();

Serial.print("SLAAP KAMER temperatuur is: ");
printTemperature(Probe02);
Serial.println();

Serial.print("BUITEN temperatuur is: ");
printTemperature(Probe03);
Serial.println();

Serial.print("WOONKAMER temperatuur is: ");
printTemperature(Probe04);
Serial.println();

Serial.print("WERK KAMER temperatuur is: ");
printTemperature(Probe05);
Serial.println();


}//--(einde loop )---

/*-----( Verklaren door gebruiker geschreven functies )-----*/
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);

if (tempC == -127.00)
{
Serial.print("Fout bij opvragen temperatuur ");
}
else
{
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}// Einde printTemperatuur
//*********( Einde )***********

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: ds18

Berichtdoor nicoverduin » 25 Jan 2015, 19:57

Gemakkelijk is een relatief begrip... Maar als je nu eerst eens goed de code bestudeert die je nu hebt voor online zie je op verschillende plaatsen "celcius" en "fahrenheit" staan. En met daarvoor en daarachter JSON of XML structuren. Als jij nu 5 variabelen wilt versturen, moet je dat voor 5 stuks doen.
Verder zie je in de setup waar hij de sensoren ontdekt. Dat moet je dan nu voor 5 stuks doen.
Tip:
Als je niet weet wat een programma doet is het handig om gewoon zelf commentaar toe te voegen... En niet iets van "variabele wordt gevuld met..." Het is namelijk niet de bedoeling dat je het afraffelt maar "leert" wat de oorspronkelijke programmeur bedoelde. En hoe meer energie je er in stopt, hoe meer je ervoor terugkijkt. En als je iets tegenkomt wat je niet kent, gewoon opzoeken.....
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

Re: ds18

Berichtdoor weske2000 » 25 Jan 2015, 20:20

Beste nico

Ik heb al een beetje met de code gespeeld.

Krijg nu .

{
"temperatureq": {
"celcius": 19.00,
"fahrenheit": 66.20
}
}
{
"temperatuq": {
"celcius": 19.00,
"fahrenheit": 66.20
}
}

Maar dit is dus de waarde van de zelfde sensor .

Kunt u me alsjeblieft helpen met 1 sensor toe te voegen dan ga ik zelf verder met de rest

Alvast vriendlijk dank Wesley

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: ds18

Berichtdoor nicoverduin » 26 Jan 2015, 00:52

Wesley,
Leren is niet kopieren...... Het programma geeft in die mooie listing van jou keurig aan hoe een variabele wordt doorgegeven. En als je ff je best doet om te kijken wat daar staat dan moet het kwartje vallen..... Je moet dus goed kijken en de tijd nemen hoe het werkt.En als je daar niet iets van begrijpt, dan gewoon hier vragen. Maar je moet er wel energie in steken....
Maar een tip.... Hoe denk jij te weten of je nu te maken hebt met welke temperatuur...... wat moet je dan doen om onderscheid te maken?
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 13
Geregistreerd: 11 Jan 2015, 16:25

Re: ds18

Berichtdoor weske2000 » 26 Jan 2015, 10:19

Beste nico

Ik denk zelf dat het hier begint heb er wel tijd ingestoken maar snap even de opzet niet

Serial.println("Reading sensor.");

float celsius;
float fahrenheit;
String error = "";

if (sensors.isConnected(outsideThermometer)) {
sensors.requestTemperatures();
celsius = sensors.getTempC(outsideThermometer);
fahrenheit = sensors.getTempF(outsideThermometer);

Serial.print("C: ");
Serial.println(celsius);
Serial.print("F: ");
Serial.println(fahrenheit);
} else {
error = "Error reading sensors";
Serial.println(error);
}

if (parsedRequest == "XML") {
sendXmlResponse(client, celsius, fahrenheit, error);
} else if (parsedRequest.startsWith("JSONP")) {
// Parse callback arguement.
String callback = parsedRequest.substring(
parsedRequest.indexOf(
'callback=')+1, parsedRequest.length())
;
callback = callback.substring(0, callback.indexOf('&'));

Serial.println("Using callback: " + callback);

sendJsonpResponse(client, celsius, fahrenheit, error,
callback);
} else {
// Default to JSON.
sendJsonResponse(client, celsius, fahrenheit, error);
}

Volgende

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: orilaefig en 32 gasten