// Configure the framework
#include "SoulissFramework.h"#include "bconf/StandardArduino.h" // Use a standard Arduino#include "conf/ethW5100.h" // Ethernet through Wiznet W5100
// Include framework code and libraries#include <SPI.h>
/*** All configuration includes should be above this line ***/ #include "Souliss.h"
// This identify the number of the LED logic#define MYLEDLOGIC1 0#define MYLEDLOGIC2 1...#define MYLEDLOGIC9 8#define MYLEDLOGIC10 9#define MYLEDLOGIC11 10
#define TEMPERATURE 11 // Identify the temperature logic#define HUMIDITY 13 // Identify the humidity logic
// Include and Configure DHT11 SENSOR#include "DHT.h"#define DHTPIN 46 // pin where connected to#define DHTTYPE DHT11 // DHT 11 DHT dht(DHTPIN, DHTTYPE, 15);#define DEADBAND 0.05 // Identify the sensor, in case of more than one used on the same board
// Define the network configuration according to your router settingsuint8_t ip_address[4] = {192, 168, 1, 79};uint8_t subnet_mask[4] = {255, 255, 255, 0};uint8_t ip_gateway[4] = {192, 168, 1, 1};#define Gateway_address 77#define Peer_address 79#define Peer2_address 78#define Peer3_address 0xAB01#define myvNet_address ip_address[3] // The last byte of the IP address (77) is also the vNet address#define myvNet_subnet 0xFF00#define myvNet_supern Gateway_address
void setup(){ Initialize();
dht.begin();
// Setup the network configuration Souliss_SetAddress(Peer_address, myvNet_subnet, myvNet_supern); // Address on the wireless interface Souliss_SetAddress(0xAB02, 0xFF00, 0x0000); // Set_SimpleLight(MYLEDLOGIC);// Define a simple LED light logic Set_SimpleLight(MYLEDLOGIC1); Set_SimpleLight(MYLEDLOGIC2); ... Set_SimpleLight(MYLEDLOGIC9); Set_SimpleLight(MYLEDLOGIC10); Set_SimpleLight(MYLEDLOGIC11);
Set_Temperature(TEMPERATURE); // Define one temperature measure Set_Humidity(HUMIDITY); // Define one humidity measure
digitalWrite(22, LOW); digitalWrite(23, LOW);... digitalWrite(30, HIGH); digitalWrite(42, LOW); digitalWrite(44, HIGH);
pinMode(22, OUTPUT); pinMode(32, INPUT); pinMode(23, OUTPUT); pinMode(33, INPUT); ... pinMode(30, OUTPUT); pinMode(40, INPUT); pinMode(42, OUTPUT); pinMode(43, INPUT); pinMode(44, OUTPUT); pinMode(45, INPUT);
}
void loop(){ // Here we start to play EXECUTEFAST() { UPDATEFAST(); FAST_50ms() { // We process the logic and relevant input and output every 50 milliseconds DigIn(32, Souliss_T1n_ToggleCmd, 0); // Use the pin2 as ON/OFF toggle command Logic_SimpleLight(MYLEDLOGIC1); // Drive the LED as per command DigOut(22, Souliss_T1n_Coil, 0); // Use the pin9 to give power to the LED according to the logic DigIn(33, Souliss_T1n_ToggleCmd, 1); // Use the pin2 as ON/OFF toggle command Logic_SimpleLight(MYLEDLOGIC2); // Drive the LED as per command DigOut(23, Souliss_T1n_Coil, 1); // Use the pin9 to give power to the LED according to the logic ...
DigIn(40, Souliss_T1n_ToggleCmd, 8); // Use the pin2 as ON/OFF toggle command Logic_SimpleLight(MYLEDLOGIC9); // Drive the LED as per command LowDigOut(30, Souliss_T1n_Coil, 8); // Use the pin9 to give power to the LED according to the logic
DigIn(43, Souliss_T1n_ToggleCmd, 9); // Use the pin2 as ON/OFF toggle command Logic_SimpleLight(MYLEDLOGIC10); // Drive the LED as per command DigOut(42, Souliss_T1n_Coil, 9); // Use the pin9 to give power to the LED according to the logic
*************** Qui comincia la parte con il SEND *******************
if ( DigIn(45, Souliss_T1n_ToggleCmd, 10)) if (digitalRead(42) == HIGH) { mOutput(0) = Souliss_T1n_OffCoil; mOutput(1) = Souliss_T1n_OffCoil; ... mOutput(8) = Souliss_T1n_OffCoil; mOutput(9) = Souliss_T1n_OffCoil; Send(Peer2_address, 0, Souliss_T1n_OffCoil); Send(Peer2_address, 1, Souliss_T1n_OffCoil); ... Send(Peer2_address, 7, Souliss_T1n_OffCoil); Send(Peer2_address, 8, Souliss_T1n_OffCoil); Send(0xAB01, 0, Souliss_T1n_OffCoil); ... Send(0xAB01, 5, Souliss_T1n_OffCoil); Logic_SimpleLight(MYLEDLOGIC11); DigOut(44, Souliss_T1n_Coil, MYLEDLOGIC11); } else { mOutput(9) = Souliss_T1n_OnCoil; Logic_SimpleLight(MYLEDLOGIC11); DigOut(44, Souliss_T1n_Coil, MYLEDLOGIC11); } }
FAST_1110ms() { // Compare previous and new input measure and provide the updates to SoulissApp Logic_Temperature(TEMPERATURE); Logic_Humidity(HUMIDITY); }
// Here we handle here the communication with Android, commands and notification // are automatically assigned to MYLEDLOGIC FAST_PeerComms();
}
EXECUTESLOW() { UPDATESLOW();
SLOW_10s() { // Read temperature and humidity from DHT every 10 seconds float h = dht.readHumidity(); // Read temperature as Celsius float t = dht.readTemperature(); // Read temperature as Fahrenheit //float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) ) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.print(" *C ");
Souliss_ImportAnalog(memory_map, TEMPERATURE, &t); Souliss_ImportAnalog(memory_map, HUMIDITY, &h); //Souliss_ImportAnalog(memory_map, TEMPERATURE, &f); }
} }
--
You received this message because you are subscribed to the Google Groups "souliss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to souliss+unsubscribe@googlegroups.com.
To post to this group, send email to sou...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/souliss/abea6755-e9a7-442b-ab24-136c9d9fb716%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#include <SPI.h>#include <Wire.h>#include <PN532_I2C.h>#include <PN532.h>
PN532_I2C pn532i2c(Wire);PN532 nfc(pn532i2c);
// Configure the framework#include "SoulissFramework.h"#include "bconf/StandardArduino.h" // Use a standard Arduino
//#include "conf/ethW5100.h"#include "conf/ethENC28J60.h" // Ethernet through Wiznet W5100//#include "conf/Gateway.h"
/*** All configuration includes should be above this line ***/ #include "Souliss.h"
// NFCconst uint8_t maxKeyLength = 7;uint8_t validKeys[][maxKeyLength] = { { 0x95, 0x83, 0x93, 0x05, 0x00, 0x00, 0x00 }, };int keyCount = sizeof validKeys / maxKeyLength;
#define Alarmon 0x0005,0x05 //definition for pblsh#define Alarmoff 0x0006,0x06 //definition for pblsh
void setup() {
Serial.begin(115200); Serial.println("Hello!");
nfc.begin();
uint32_t vdt = nfc.getFirmwareVersion(); if (! vdt) { Serial.print("Didn't find PN53x board"); while (1); // halt } // Got ok data, print it out! Serial.print("Found chip PN5"); Serial.println((vdt>>24) & 0xFF, HEX); Serial.print("Firmware ver. "); Serial.print((vdt>>16) & 0xFF, DEC); Serial.print('.'); Serial.println((vdt>>8) & 0xFF, DEC); // Set the max number of retry attempts to read from a card // This prevents us from waiting forever for a card, which is // the default behaviour of the PN532. nfc.setPassiveActivationRetries(0xFF); // configure board to read RFID tags nfc.SAMConfig(); Serial.println("Waiting for an ISO14443A card");
pinMode(2, INPUT); // Hardware pulldown required pinMode(7, OUTPUT); // Power the LED pinMode(9, OUTPUT); // Power the LED}
void loop(void) {
boolean success; uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) // Wait for an ISO14443A type cards (Mifare, etc.). When one is found // 'uid' will be populated with the UID, and uidLength will indicate // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); if (success) { //Serial.println("Found a card!"); Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes"); Serial.print("UID Value: "); for (uint8_t i=0; i < uidLength; i++) { Serial.print(" 0x");Serial.print(uid[i], HEX); } Serial.println("");
bool valid = false; // Compare this key to the valid once registered here in sketch for (int i=0;i<keyCount && !valid;i++) { for (int j=0;j<uidLength && !valid;j++) { if (uid[j] != validKeys[i][j]) { break; } if (j==uidLength-1) { valid = true; } } } if (valid) {
if (digitalRead (9) == HIGH) { digitalWrite(9, LOW); digitalWrite(7, LOW);// pblsh(Alarmoff); // freezes the node } else { digitalWrite(9, HIGH); digitalWrite(7, HIGH);// pblsh(Alarmon); // freezes the node }
Serial.println("valed"); Serial.println(digitalRead (9)); } // wait until the card is taken away while (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength)) {} } else {
// PN532 probably timed out waiting for a card // Serial.println("Timed out waiting for a card"); } }