Ksduino-tests1

From ArduinoInfo
Jump to navigation Jump to search

KSDUINO TESTS:


Below are Arduino test sketches for sending data to ksduino.org
For information about ksduino see https://ksduino.org/

UNDER CONSTRUCTION: This will be a how-to page for KSduino with several examples.

Latest Example:

- Testing: sending outdoor AND INDOOR Temp, Outdoor Humidity, Outdoor Light Level
- SEE this live data here: https://ksduino.org/?devices&device_id=3330
- Test of sending data to ksduino. See: https://ksduino.org/
- Sending Temperature and Humidity data from DHT11 Sensor
- Sending temperature from DS18B20 Sensors
- Sending light level from PhotoResistor network
/* YourDuinoStarter Example: TerryKing_Temp_Humid_Outdoor02 - Testing: sending outdoor and indoor Temp,Humidity,Light - Test of sending data to ksduino. See: https://ksduino.org/ - Sending Temperature and Humidity data from DHT11 Sensor - Sending temperature from DS18B20 Sensors - Sending light level from PhotoResistor network - Read DHT11 type sensor. See: https://arduinoinfo.mywikis.net/wiki/DHT11-Humidity-TempSensor - SEE the comments after "//" on each line below - CONNECTIONS: - DHT11 Sensor: +5V, Gnd, Signal to PIN 5 - DS18B20 Sensors: +5V, Gnd, Signal to pin 3 - PhotoResistor Light Level sensor: Pin A2 - * KSduino library & examples is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - V1.00` 15 Jan 2013 Questions: terry@yourduino.com */ /*-----( Import needed libraries )-----*/ // Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html #include <OneWire.h> // 1-wire bus including DS18B20 //Get DallasTemperature Library here: http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library #include <DallasTemperature.h> // Read temperature from DS18B20 #include <dht11.h> // From Rob Tillaart: http://playground.arduino.cc/Main/DHTLib #include <SPI.h> // Standard Arduino Library #include <EthernetUdp.h> // ksduino library from https://ksduino.org/?downloads #include <KSduino.h> // ksduino library from https://ksduino.org/?downloads /*-----( Declare Constants and Pin Numbers )-----*/ #define DHT11PIN 5 // The Temperature/Humidity sensor #define ONE_WIRE_BUS 3 // DS18B20 #define PHOTO_RES_PIN A2 // Analog input 2 /*-----(THESE VALUES MUST BE CHANGED FOR EVERY NEW USER AND DEVICE )-----*/ // device ID & Password (received from "add New Device" at http://ksduino.org/?devices ) unsigned int deviceID = 3330; unsigned int devicePwd = 1234; // MUST be a 4-digit number /*-----(THESE VALUES MUST BE CHANGED ONCE for each new Ethernet Interface on your local network )-----*/ // Available IP Address on YOUR LOCAL NETWORK (see Instructions) byte ip[] = { 192, 168, 1, 126 }; /*-----(UNIQUE MAC ADDRESS for your Ethernet shield/module )-----*/ // Use this one unless your unit has an assigned MAC address (may be on a sticker on board) // If you have 2 or more Arduinos on your local network their MAC must be different byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }; /*-----(DO NOT CHANGE THESE VALUES )-----*/ unsigned int port = 58833; // Local UDP port number byte serverIp[] = { 178,63,53,233 }; // KSduino Server address & port unsigned int serverPort = 9930; // Server UDP port number /*-----( Declare objects )-----*/ KSduino ksd (deviceID, devicePwd, serverIp, serverPort); // Create KSduino class dht11 DHT11; // Create the DHT11 sensor object OneWire ourWire(ONE_WIRE_BUS); // Set up a oneWire instance /* Tell Dallas Temperature Library to use oneWire Library */ DallasTemperature sensors(&ourWire); /*-----( Declare Global Variables )-----*/ // DHTll Temperature-Humidity Sensor Variables float OutDoorTempDH_C, OutDoorTempDH_F, Humidity, DewPoint; // Variables from DHT11 Sensor, calculations. // Photoresistor Light Level Sensor Variables float PhotoResistorVoltageRaw; float PhotoResistorVoltage; float LightLevelPercent; // DS18B20 Temperature Sensor Variables int OutDoorTempDS_C; // Value returned from DS18B20 chip int OutDoorTempDS_F; // Value returned from DS18B20 chip int InDoorTempDS_C; // Value returned from DS18B20 chip int InDoorTempDS_F; // Value returned from DS18B20 chip char message_buf[32]; // the message buffer 32 bytes length // -------( End of Declaration section )-------------------------------------------- void setup() /****** SETUP: RUNS ONCE ******/ { Serial.begin(9600); //Ready to send debug info to Serial Monitor Serial.println("Outdoor Sensors: Starting Data send to ksduino..."); ksd.begin (mac, ip, port); // Start ksduino }//--(end setup )--- // ---------------------------------------------------------------------------------- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { /*-----------( Read the DHT11 Temperature / Humidity Sensor, and check for errors. )-----*/ Serial.println("===========( DHT11 DATA )=========="); Serial.print("Read DHT11 sensor: "); int chk = DHT11.read(DHT11PIN); switch (chk) { case 0: Serial.println("OK"); break; case -1: Serial.println("Checksum error"); break; case -2: Serial.println("Time out error"); break; default: Serial.println("Unknown error"); break; }// End case OutDoorTempDH_C = (float)DHT11.temperature,2; // Value from Sensor OutDoorTempDH_F = Fahrenheit(DHT11.temperature); // Computed value from C Humidity = (float)DHT11.humidity; // Value from Sensor DewPoint = dewPointFast(DHT11.temperature, DHT11.humidity); // Computed Value Serial.print("Humidity (%): "); Serial.println((float)Humidity, 2); Serial.print("Temperature (oC): "); Serial.println(OutDoorTempDH_C, 2); Serial.print("Temperature (oF): "); Serial.println(OutDoorTempDH_F, 2); /*-----------( Read the DS18B20 Temperature Sensor, and check for errors. )-----*/ Serial.println("=======(DS18B20 DATA )============="); Serial.println(); Serial.print("Requesting DS18B20 temperature..."); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("DONE"); OutDoorTempDS_C = sensors.getTempCByIndex(0); Serial.print("Device 1 (index 0) = "); Serial.print(OutDoorTempDS_C); Serial.println(" Degrees C"); OutDoorTempDS_F = sensors.getTempFByIndex(0); Serial.print("Device 1 (index 0) = "); Serial.print(OutDoorTempDS_F); Serial.println(" Degrees F"); InDoorTempDS_C = sensors.getTempCByIndex(1); Serial.print("Device 1 (index 1) = "); Serial.print(InDoorTempDS_C); Serial.println(" Degrees C"); InDoorTempDS_F = sensors.getTempFByIndex(1); Serial.print("Device 1 (index 1) = "); Serial.print(InDoorTempDS_F); Serial.println(" Degrees F"); /*-----------( Read the PhotoResistor Sensor, Calculate Light Level )-----*/ Serial.println(); Serial.print("Read PhotoResistor Voltage "); PhotoResistorVoltageRaw = analogRead(PHOTO_RES_PIN); PhotoResistorVoltage = map(PhotoResistorVoltageRaw, 0, 1023, 5.0, 0.0); Serial.print("PhotoResistor Voltage = "); Serial.println(PhotoResistorVoltage,2); LightLevelPercent = map(PhotoResistorVoltageRaw, 0, 1023, 100.0, 0.0); Serial.print("Light Level % = "); Serial.println(LightLevelPercent); /*------( Create the message to be displayed on far right )------------------------------*/ strcpy(message_buf, "IN and OUTdoors!"); /*------( BUILD THE PACKET TO SEND TO KSduino )------------------------------*/ // Send parameters to KSduino server ksd.beginPacket (); ksd.addParameter ("f1", OutDoorTempDS_C); ksd.addParameter ("f2", OutDoorTempDS_F); ksd.addParameter ("f3", InDoorTempDS_C); ksd.addParameter ("f4", InDoorTempDS_F); ksd.addParameter ("f5", Humidity); ksd.addParameter ("f6", DewPoint); ksd.addParameter ("f7", LightLevelPercent); ksd.addMessage (message_buf); ksd.endPacket (); // Send data to ksduino Server as UDP packet ksd.update (); //-------( Delay before next update loop )-------------------------------------- delay (10000); }//--(end main loop )--- /*------------------( Declare User-written Functions )-----------------------*/ /*--------( Calculate Fahrenheit from C )----------*/ double Fahrenheit(double celsius) { return 1.8 * celsius + 32; } /*------------( Calculate Dew Point )---------------*/ // reference: http://en.wikipedia.org/wiki/Dew_point double dewPointFast(double celsius, double humidity) { double a = 17.271; double b = 237.7; double temp = (a * celsius) / (b + celsius) + log(humidity/100); double Td = (b * temp) / (a - temp); return Td; } //*********( THE END )***********








- Testing: sending outdoor Temp,Humidity,Light
- Test of sending data to ksduino. See: https://ksduino.org/
- Sending Temperature and Humidity data from DHT11 Sensor
- Sending temperature from DS18B20 Sesnor
- Sending light level from PhotoResistor network

/* YourDuinoStarter Example: 
 TerryKing_Temp_Humid_Outdoor01
 - Testing: sending outdoor Temp,Humidity,Light
 - Test of sending data to ksduino. See: https://ksduino.org/
 - Sending Temperature and Humidity data from  DHT11 Sensor
 - Sending temperature from DS18B20 Sesnor
 - Sending light level from PhotoResistor network
 - Read DHT11 type sensor. See: https://arduinoinfo.mywikis.net/wiki/DHT11-Humidity-TempSensor 
 
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
 - DHT11 Sensor:     +5V, Gnd, Signal to PIN 5
 - DS18B20 Sensor:   +5V, Gnd, Signal to pin 3
 - PhotoResistor Light Level sensor: Pin A2

 - 
 * KSduino library & examples is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.  
 
 - V1.00` 15 Jan 2013
 Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>      // 1-wire bus including DS18B20 

//Get DallasTemperature Library here:  http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>  // Read temperature from DS18B20

#include <dht11.h>        // From Rob Tillaart: http://playground.arduino.cc/Main/DHTLib

#include <SPI.h>          // Standard Arduino Library
#include <EthernetUdp.h>  // ksduino library from https://ksduino.org/?downloads
#include <KSduino.h>      // ksduino library from https://ksduino.org/?downloads

/*-----( Declare Constants and Pin Numbers )-----*/
#define DHT11PIN     5 // The Temperature/Humidity sensor
#define ONE_WIRE_BUS 3 // DS18B20
#define PHOTO_RES_PIN A2  // Analog input 2

/*-----(THESE VALUES MUST BE CHANGED FOR EVERY NEW USER AND DEVICE )-----*/

// device ID & Password (received from "add New Device" at http://ksduino.org/?devices )
unsigned int deviceID   = 3330;
unsigned int devicePwd  = 1234;  // MUST be a 4-digit number  

/*-----(THESE VALUES MUST BE CHANGED ONCE for each new Ethernet Interface on your local network  )-----*/
// Available IP Address on YOUR LOCAL NETWORK (see Instructions)
byte ip[] = { 192, 168, 1, 126 };

/*-----(UNIQUE MAC ADDRESS for your Ethernet shield/module  )-----*/
// Use this one unless your unit has an assigned MAC address (may be on a sticker on board)
// If you have 2 or more Arduinos on your local network their MAC must be different
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D };

/*-----(DO NOT CHANGE THESE VALUES  )-----*/
unsigned int port       = 58833;              // Local UDP port number
byte         serverIp[] = { 178,63,53,233 };  // KSduino Server address & port
unsigned int serverPort = 9930;               // Server UDP port number

/*-----( Declare objects )-----*/
KSduino ksd (deviceID, devicePwd, serverIp, serverPort); // Create KSduino class

dht11 DHT11;  // Create the DHT11 sensor object

OneWire ourWire(ONE_WIRE_BUS);  // Set up a oneWire instance 

/* Tell Dallas Temperature Library to use oneWire Library */
DallasTemperature sensors(&ourWire);

/*-----( Declare Global Variables )-----*/

// DHTll Temperature-Humidity Sensor Variables
float OutDoorTempDH_C, OutDoorTempDH_F, Humidity, DewPoint;   // Variables from DHT11 Sensor, calculations.

// Photoresistor Light Level Sensor Variables
float PhotoResistorVoltageRaw;
float PhotoResistorVoltage;
float LightLevelPercent;

// DS18B20 Temperature Sensor Variables
int    OutDoorTempDS_C;  // Value returned from DS18B20 chip
int    OutDoorTempDS_F;  // Value returned from DS18B20 chip

char   message_buf[32];  // the message buffer 32 bytes length

// -------( End of Declaration section )--------------------------------------------

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);  //Ready to send debug info to Serial Monitor
  Serial.println("Outdoor Sensors: Starting Data send to ksduino...");

  ksd.begin (mac, ip, port);     // Start ksduino 
}//--(end setup )---

// ----------------------------------------------------------------------------------

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{

  /*-----------( Read the DHT11 Temperature / Humidity Sensor, and check for errors. )-----*/

  Serial.println("===========( DHT11 DATA )==========");
  Serial.print("Read DHT11 sensor: ");

  int chk = DHT11.read(DHT11PIN);
  switch (chk)
  {
  case  0:  Serial.println("OK");  break;
  case -1:  Serial.println("Checksum error");  break;
  case -2:  Serial.println("Time out error");  break;
  default:  Serial.println("Unknown error");   break;
  }// End case  

  OutDoorTempDH_C  =  (float)DHT11.temperature,2;     // Value from Sensor
  OutDoorTempDH_F  =  Fahrenheit(DHT11.temperature);  // Computed value from C
  Humidity         =  (float)DHT11.humidity;          // Value from Sensor
  DewPoint         =  dewPointFast(DHT11.temperature, DHT11.humidity); // Computed Value  

  Serial.print("Humidity (%): ");
  Serial.println((float)Humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println(OutDoorTempDH_C, 2);

  Serial.print("Temperature (oF): ");
  Serial.println(OutDoorTempDH_F, 2);

  /*-----------( Read the DS18B20 Temperature Sensor, and check for errors. )-----*/
  Serial.println("=======(DS18B20 DATA )=============");

  Serial.println();
  Serial.print("Requesting DS18B20 temperature...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  OutDoorTempDS_C = sensors.getTempCByIndex(0);
  Serial.print("Device 1 (index 0) = ");
  Serial.print(OutDoorTempDS_C);
  Serial.println(" Degrees C");

  OutDoorTempDS_F = sensors.getTempFByIndex(0);
  Serial.print("Device 1 (index 0) = ");
  Serial.print(OutDoorTempDS_F);
  Serial.println(" Degrees F");

  /*-----------( Read the PhotoResistor Sensor, Calculate Light Level )-----*/
  Serial.println();
  Serial.print("Read PhotoResistor Voltage ");

  PhotoResistorVoltageRaw = analogRead(PHOTO_RES_PIN);

  PhotoResistorVoltage =
    map(PhotoResistorVoltageRaw, 0, 1023, 5.0, 0.0);
  Serial.print("PhotoResistor Voltage = ");
  Serial.println(PhotoResistorVoltage,2);

  LightLevelPercent =
    map(PhotoResistorVoltageRaw, 0, 1023, 100.0, 0.0);
  Serial.print("Light Level % = ");
  Serial.println(LightLevelPercent);
 /*------( Create the message to be displayed on far right )------------------------------*/
  strcpy(message_buf, "OutDoor Conditions");

/*------( BUILD THE PACKET TO SEND TO KSduino )------------------------------*/
  // Send parameters to KSduino server
  ksd.beginPacket ();
    ksd.addParameter ("f1",  OutDoorTempDS_C);
    ksd.addParameter ("f2",  OutDoorTempDS_F);

    ksd.addParameter ("f3",  OutDoorTempDH_C);
    ksd.addParameter ("f4",  OutDoorTempDH_F);
    ksd.addParameter ("f5",  Humidity);
    ksd.addParameter ("f6",  DewPoint);

    ksd.addParameter ("f7",  LightLevelPercent);

    ksd.addMessage (message_buf);

  ksd.endPacket ();


// Send data to ksduino Server as UDP packet
  ksd.update ();

//-------( Delay before next update loop )--------------------------------------
  delay (2000);

}//--(end main loop )---


/*------------------( Declare User-written Functions )-----------------------*/

/*--------( Calculate Fahrenheit from C )----------*/

double Fahrenheit(double celsius)
{
  return 1.8 * celsius + 32;
}

/*------------( Calculate Dew Point )---------------*/
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
  double a = 17.271;
  double b = 237.7;
  double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  double Td = (b * temp) / (a - temp);
  return Td;
}
//*********( THE END )***********







/* YourDuinoStarter Example:
TerryKing_Temperature_DS18B20_1
- Testing: sending temperature data from DS18B20 electronic thermometers
- Testing: Send text message depending on temperature
- Test of sending data to ksduino. See: https://ksduino.org/

/* YourDuinoStarter Example: 
 TerryKing_Temperature_DS18B20_1
 - Testing: sending temperature data from DS18B20 electronic thermometers
 - Testing: Send text message depending on temperature
 - Test of sending data to ksduino. See: https://ksduino.org/
 
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
 - DS18B20"  Gnd, +5V, Signal to pin 2
 
 - 
 * KSduino library & examples is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.  
 
 - V1.00` 16 Jan 2013
 Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/

#include <SPI.h>          // Standard Arduino Library: needed for Ethernet
#include <EthernetUdp.h>  // ksduino library from https://ksduino.org/?downloads
#include <KSduino.h>      // ksduino library from https://ksduino.org/?downloads
#include <OneWire.h>      // For 1-wire bus devices, including DS18B20
#include <DallasTemperature.h>  // Read temperature from DS18B20

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS 2 /*-(Connect to Pin 2 )-*/

/*-----(THESE VALUES MUST BE CHANGED FOR EVERY NEW USER AND DEVICE )-----*/

// device ID & Password (received from "add New Device" at http://ksduino.org/?devices )
unsigned int deviceID   = 3326;
unsigned int devicePwd  = 1234;  // MUST be a 4-digit number  

/*-----(THESE VALUES MUST BE CHANGED ONCE for each new Ethernet Interface on your local network  )-----*/
// Available IP Address on YOUR LOCAL NETWORK (see Instructions)
byte ip[] = { 192, 168, 1, 126 };

/*-----(UNIQUE MAC ADDRESS for your Ethernet shield/module  )-----*/
// Use this one unless your unit has an assigned MAC address (may be on a sticker on board)
// If you have 2 or more Arduinos on your local network their MAC must be different
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D };

/*-----(DO NOT CHANGE THESE VALUES  )-----*/
unsigned int port       = 58833;              // Local UDP port number
byte         serverIp[] = {
  178,63,53,233 };  // KSduino Server address & port
unsigned int serverPort = 9930;               // Server UDP port number

/*-----( Declare objects )-----*/
KSduino ksd (deviceID, devicePwd, serverIp, serverPort); // Create KSduino class
OneWire ourWire(ONE_WIRE_BUS);  // Set up a oneWire instance 

/* Tell Dallas Temperature Library to use oneWire Library */
DallasTemperature sensors(&ourWire);

/*-----( Declare Global Variables )-----*/
// Define variables for Sensor data 
int    Therm1C;  // Value returned from DS18B20 chip
int    Therm1F;  // Value returned from DS18B20 chip

char   message_buf[32];  // the message buffer 32 bytes length

// -------( End of Declaration section )--------------------------------------------

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);  //Ready to send debug info to Serial Monitor
  Serial.println("Starting Data send to ksduino...");

  ksd.begin (mac, ip, port);   // Start ksduino 
  sensors.begin();             // Start up the DallasTemperature library
}//--(end setup )---

// ----------------------------------------------------------------------------------

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{

  /*-----------( Read the DS18B20 Temperature )-----*/

  Serial.println("=================================");

  Serial.println();
  Serial.print("Requesting temperature...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  Therm1C = sensors.getTempCByIndex(0);
  Serial.print("Device 1 (index 0) = ");
  Serial.print(Therm1C);
  Serial.println(" Degrees C");

  Therm1F = sensors.getTempFByIndex(0);
  Serial.print("Device 1 (index 0) = ");
  Serial.print(Therm1F);
  Serial.println(" Degrees F");


  strcpy(message_buf, "Indoor Temp");
  if (Therm1F > 75.0) { strcpy(message_buf, "Turn Down Stove!"); }
  if (Therm1F < 65.0) { strcpy(message_buf, "Add Wood to Stove!"); }


  // Build Data Packet to Send parameters to KSduino server
  ksd.beginPacket ();
  ksd.addParameter ("f1",  Therm1C);
  ksd.addParameter ("f2",  Therm1F);
  ksd.addMessage (message_buf);
  ksd.endPacket ();


  // Send data to ksduino Server as UDP packet
  ksd.update ();

  //-------( Delay before next update loop )--------------------------------------
  delay (2000); // Send every 2 seconds

}//--(end main loop )---


/*------------------( Declare User-written Functions )-----------------------*/


//*********( THE END )***********









/* YourDuinoStarter Example:
TerryKing_Potentiometer1
- Testing: Rapidly sending realtime analog data from Potentiometer
- Testing: Send text message depending on voltage
- Test of sending data to ksduino. See: https://ksduino.org/
Here's what the KSduino screen looks like when you change the pot quickly:
TerryKing_Potentiometer1.jpg
Following can be cut-pasted into Arduinno IDE:
/* YourDuinoStarter Example: TerryKing_Potentiometer1 - Testing: sending analog data from Potentiometer - Testing: Send text message depending on voltage - Test of sending data to ksduino. See: https://ksduino.org/ - SEE the comments after "//" on each line below - CONNECTIONS: - Potentiometer: +5V, Gnd, Signal to PIN 2 - * KSduino library & examples is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - V1.00` 15 Jan 2013 Questions: terry@yourduino.com */ /*-----( Import needed libraries )-----*/ // #include <SPI.h> // Standard Arduino Library #include <SPI.h> // Standard Arduino Library #include <EthernetUdp.h> // ksduino library from https://ksduino.org/?downloads #include <KSduino.h> // ksduino library from https://ksduino.org/?downloads /*-----( Declare Constants and Pin Numbers )-----*/ #define PotentiometerPin A2 /*-----(THESE VALUES MUST BE CHANGED FOR EVERY NEW USER AND DEVICE )-----*/ // device ID & Password (received from "add New Device" at http://ksduino.org/?devices ) unsigned int deviceID = 3324; unsigned int devicePwd = 1234; // MUST be a 4-digit number /*-----(THESE VALUES MUST BE CHANGED ONCE for each new Ethernet Interface on your local network )-----*/ // Available IP Address on YOUR LOCAL NETWORK (see Instructions) byte ip[] = { 192, 168, 1, 126 }; /*-----(UNIQUE MAC ADDRESS for your Ethernet shield/module )-----*/ // Use this one unless your unit has an assigned MAC address (may be on a sticker on board) // If you have 2 or more Arduinos on your local network their MAC must be different byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }; /*-----(DO NOT CHANGE THESE VALUES )-----*/ unsigned int port = 58833; // Local UDP port number byte serverIp[] = { 178,63,53,233 }; // KSduino Server address & port unsigned int serverPort = 9930; // Server UDP port number /*-----( Declare objects )-----*/ KSduino ksd (deviceID, devicePwd, serverIp, serverPort); // Create KSduino class /*-----( Declare Global Variables )-----*/ // Define variables for Sensor data int AnalogValue; // Value 0..1024 returned from 10-bit analog input float Voltage; // Variable from potentiometer char message_buf[32]; // the message buffer 32 bytes length // -------( End of Declaration section )-------------------------------------------- void setup() /****** SETUP: RUNS ONCE ******/ { Serial.begin(9600); //Ready to send debug info to Serial Monitor Serial.println("Starting Data send to ksduino..."); ksd.begin (mac, ip, port); // Start ksduino }//--(end setup )--- // ---------------------------------------------------------------------------------- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { /*-----------( Read the DHT11 Temperature / Humidity Sensor, and check for errors. )-----*/ Serial.println("================================="); Serial.print("Read Potentiometer value: "); AnalogValue = analogRead(PotentiometerPin); Serial.print("Analog Raw Value = "); Serial.println(AnalogValue); Voltage = map(AnalogValue, 0, 1023, 0, 5000); Voltage = Voltage * .001; Serial.print("Analog Voltage = "); Serial.println(Voltage); strcpy(message_buf, "Voltage OK"); if (Voltage < 1.0) { strcpy(message_buf, "Voltage Too LOW"); } if (Voltage > 4.0) { strcpy(message_buf, "Voltage Too HIGH"); } // Build Data Packet to Send parameters to KSduino server ksd.beginPacket (); ksd.addParameter ("f1", Voltage); ksd.addMessage (message_buf); ksd.endPacket (); // Send data to ksduino Server as UDP packet ksd.update (); //-------( Delay before next update loop )-------------------------------------- delay (250); // Send 4 values per second! }//--(end main loop )--- /*------------------( Declare User-written Functions )-----------------------*/ //*********( THE END )***********






TerryKing_Temp_Humid_01
Test of sending 4 float values to ksduino
Sends TempC, TempF, Humidity, Dew Point from DHT11 sensor
/* YourDuinoStarter Example: TerryKing_Temp_Humid_01 - Test of sending data to ksduino. See: https://ksduino.org/ - Sending Temperature and Humidity data from DHT11 Sensor - Read DHT11 type sensor. See: https://arduinoinfo.mywikis.net/wiki/DHT11-Humidity-TempSensor - SEE the comments after "//" on each line below - CONNECTIONS: - DHT11 Sensor: +5V, Gnd, Signal to PIN 2 - * KSduino library & examples is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - V1.01` 14 Jan 2013 Questions: terry@yourduino.com */ /*-----( Import needed libraries )-----*/ #include <dht11.h> // From Rob Tillaart: http://playground.arduino.cc/Main/DHTLib #include <SPI.h> // Standard Arduino Library #include <EthernetUdp.h> // ksduino library from https://ksduino.org/?downloads #include <KSduino.h> // ksduino library from https://ksduino.org/?downloads /*-----( Declare Constants and Pin Numbers )-----*/ #define DHT11PIN 2 // The Temperature/Humidity sensor /*-----(THESE VALUES MUST BE CHANGED FOR EVERY NEW USER AND DEVICE )-----*/ // device ID & Password (received from "add New Device" at http://ksduino.org/?devices ) unsigned int deviceID = 3322; unsigned int devicePwd = 1234; // MUST be a 4-digit number /*-----(THESE VALUES MUST BE CHANGED ONCE FOR EACH NEW USER )-----*/ // Available IP Address on YOUR LOCAL NETWORK (see Instructions) byte ip[] = { 192, 168, 1, 126 }; /*-----(UNIQUE MAC ADDRESS for your Ethernet shield/module )-----*/ // Use this one unless your unit has an assigned MAC address. // If you have 2 or more Arduinos on your local network their MAC must be different byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }; /*-----(DO NOT CHANGE THESE VALUES )-----*/ unsigned int port = 58833; // Local UDP port number byte serverIp[] = { 178,63,53,233 }; // KSduino Server address & port unsigned int serverPort = 9930; /*-----( Declare objects )-----*/ KSduino ksd (deviceID, devicePwd, serverIp, serverPort); // Create KSduino class dht11 DHT11; // Declare the DHT11 sensor object /*-----( Declare Global Variables )-----*/ // Define variables for Sensor data float TempC, TempF, Humidity, DewPoint; // Variables from DHT11 Sesnor, calculations. // -------( End of Declaration section )-------------------------------------------- void setup() /****** SETUP: RUNS ONCE ******/ { Serial.begin(9600); //Ready to send debug info to Serial Monitor Serial.println("Starting Data send to ksduino..."); ksd.begin (mac, ip, port); // Start KSduino }//--(end setup )--- // ---------------------------------------------------------------------------------- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { /*-----------( Read the DHT11 Temperature / Humidity Sensor, and check for errors. )-----*/ Serial.println("================================="); Serial.print("Read sensor: "); int chk = DHT11.read(DHT11PIN); switch (chk) { case 0: Serial.println("OK"); break; case -1: Serial.println("Checksum error"); break; case -2: Serial.println("Time out error"); break; default: Serial.println("Unknown error"); break; }// End case TempC = (float)DHT11.temperature,2; // Value from Sensor TempF = Fahrenheit(DHT11.temperature); // Computed value from C Humidity = (float)DHT11.humidity; // Value from Sensor DewPoint = dewPointFast(DHT11.temperature, DHT11.humidity); // Computed Value // Send parameters to KSduino server ksd.beginPacket (); ksd.addParameter ("f1", TempC); ksd.addParameter ("f2", TempF); ksd.addParameter ("f3", Humidity); ksd.addParameter ("f4", DewPoint); ksd.endPacket (); // Send data to ksduino Server as UDP packet ksd.update (); //-------( Delay before next update loop )-------------------------------------- delay (2000); }//--(end main loop )--- /*------------------( Declare User-written Functions )-----------------------*/ /*--------( Calculate Fahrenheit from C )----------*/ double Fahrenheit(double celsius) { return 1.8 * celsius + 32; } /*------------( Calculate Dew Point )---------------*/ // reference: http://en.wikipedia.org/wiki/Dew_point double dewPointFast(double celsius, double humidity) { double a = 17.271; double b = 237.7; double temp = (a * celsius) / (b + celsius) + log(humidity/100); double Td = (b * temp) / (a - temp); return Td; } //*********( THE END )***********






TerryKing_Test_ksduino_05
- Test of sending data to ksduino
- Based on example simple_03 by kirill@ksduino.org

/* YourDuinoStarter Example: 
 TerryKing_Test_ksduino_05
 - Test of sending data to ksduino
 - Based on example simple_03 by kirill@ksduino.org
 - SEE the comments after "//" on each line below
 - CONNECTIONS:
 - None
 - 
 * KSduino library & examples is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.  
 
 - V1.03 14 Jan 2013
 Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>          // Standard Arduino Library
#include <EthernetUdp.h>  // ksduino library from https://ksduino.org/?downloads
#include <KSduino.h>      // ksduino library from https://ksduino.org/?downloads

/*-----( Declare Constants and Pin Numbers )-----*/

/*-----(THESE VALUES MUST BE CHANGED FOR EVERY NEW USER AND DEVICE )-----*/

// device ID & Password (received from "add New Device" at http://ksduino.org/?devices )
unsigned int deviceID   = 3321;
unsigned int devicePwd  = 1234;  // MUST be a 4-digit number  

/*-----(THESE VALUES MUST BE CHANGED ONCE FOR EACH NEW USER  )-----*/
// Available IP Address on YOUR LOCAL NETWORK (see Instructions)
byte ip[] = { 192, 168, 1, 126 };

/*-----(UNIQUE MAC ADDRESS for your Ethernet shield/module  )-----*/
// Use this one unless your unit has an assigned MAC address.
// If you have 2 or more Arduinos on your local network their MAC must be different
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D };

/*-----(DO NOT CHANGE THESE VALUES  )-----*/
unsigned int port       = 58833;              // Local UDP port number
byte         serverIp[] = { 178,63,53,233 };  // KSduino Server address & port
unsigned int serverPort = 9930;

/*-----( Declare objects )-----*/
KSduino ksd (deviceID, devicePwd, serverIp, serverPort); // Create KSduino class

/*-----( Declare Global Variables )-----*/
// none
// -------( End of Declaration section )--------------------------------------------

void setup()   /****** SETUP: RUNS ONCE ******/
{
  ksd.begin (mac, ip, port);     // Start KSduino 
}//--(end setup )---

// ----------------------------------------------------------------------------------

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  static byte d_value = LOW;  // Variables for example
  String buffer = "";

  // Cause the d1 value to change back and forth between HIGH and LOW each time. 
  if (d_value == LOW) d_value = HIGH;
  else  d_value = LOW;

  // Create text buffer with parameter d1 in it
  // 'buffer' is a String that starts out blank
  buffer += "d1=";  // add "d1=LOW" or "d1=HIGH" to the string 
  buffer += d_value;

  // Send String object with parameters & values to KSduino server
  ksd.sendBuffer (buffer);

  // Do delay
  delay (1000);

  // At the end of Loop, send the data to ksduino Server
  ksd.update ();

}//--(end main loop )---


/*-----( Declare User-written Functions )-----*/
//(none)
//*********( THE END )***********