Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. /* Download WifiManager from https://github.com/tzapu/WiFiManager */
  2. /*
  3. With this Example you don't need to configure SSID and Password before compile and load the sketch.
  4. If your node doesn't connect to your WiFi or isn't configured yet you will see an open WiFi network called "Souliss",
  5. connect to the wifi and open on your browser this address: http://192.168.4.1 and configure your WiFi,
  6. then you can open your Souliss Android App and enjoy! :)
  7. *(Chrome on Android not supported)
  8. */
  9. #include <WiFiClient.h>
  10. #include <EEPROM.h>
  11. #include <ESP8266mDNS.h>
  12. #include <WiFiManager.h>
  13.  
  14. WiFiManager wifi(0);
  15.  
  16. /**************************************************************************
  17. Souliss - Espressif ESP8266-Esp12
  18.  
  19. This is the Souliss Gateway, it has DHT11 for Temp & Hum, and PIR sensor
  20. for Main Antitheft System, add a blink led for a sign if the Gateway is
  21. connected to wifi network.
  22.  
  23. ***************************************************************************/
  24.  
  25. // Configure the framework
  26. #include "bconf/MCU_ESP8266.h" // Load the code directly on the ESP8266
  27. #include <SPI.h>
  28. #include "conf/DynamicAddressing.h" // Use dynamic address
  29.  
  30. // Include framework code and libraries
  31. #include <ESP8266WiFi.h>
  32. #include "Souliss.h"
  33. #include <DHT.h>
  34.  
  35. //PIN DHT
  36. #define DHTPIN 4 // Used GPI4 as digital input from dht11
  37.  
  38. //PIN for Blink as sign if the node is running
  39. #define BLINK 5
  40.  
  41. // This identify the Slot number of typicals
  42. #define TEMPERATURE 0 // This is the memory slot used for DHT11 Temp
  43. #define HUMIDITY 2 // This is the memory slot used for DHT11 Humidity
  44. #define DEADBAND 0.01 // Deadband value 1%
  45. #define ANTITHEFT 4 // This is the memory slot used for the execution of the anti-theft
  46. #define WATCHDOG 5
  47.  
  48. // Setup the DHT sensor
  49. DHT dht(DHTPIN, DHT11, 15);
  50.  
  51. void setup(){
  52. Serial.begin(115200);
  53. wifi.autoConnect("Souliss");
  54. WiFi.mode(WIFI_STA);
  55.  
  56. Initialize();
  57.  
  58. // This board request an address to the gateway at runtime, no need
  59. // to configure any parameter here.
  60. GetIPAddress();
  61. SetDynamicAddressing();
  62. GetAddress();
  63.  
  64.  
  65. // Set the typical to use
  66. Souliss_SetT52(memory_map, TEMPERATURE);
  67. Souliss_SetT53(memory_map, HUMIDITY);
  68.  
  69. // Setup the anti-theft
  70. Set_T42(ANTITHEFT);
  71.  
  72. pinMode(2, INPUT); // Use pin GPI02 as digital input for PIR
  73. pinMode(BLINK, OUTPUT); // use pin 5 as Blink Led
  74. dht.begin();
  75. }
  76.  
  77. void loop(){
  78. // Here we start to play
  79. EXECUTEFAST() {
  80. UPDATEFAST();
  81.  
  82. FAST_50ms(){
  83. if (WiFi.status() == WL_CONNECTED) {
  84. digitalWrite(BLINK, !digitalRead(BLINK));
  85.  
  86. }
  87. }
  88.  
  89. FAST_510ms(){
  90. // Retreive data from the MaCaco communication channel
  91. Souliss_CommunicationData(memory_map, &data_changed);
  92.  
  93. // Compare the acquired input with the stored one, send the new value to the
  94. // user interface if the difference is greater than the deadband
  95.  
  96. Souliss_Logic_T52(memory_map, TEMPERATURE, DEADBAND, &data_changed);
  97. Souliss_Logic_T53(memory_map, HUMIDITY, DEADBAND, &data_changed);
  98.  
  99.  
  100. }
  101.  
  102. // Here we handle here the communication with Android
  103. FAST_PeerComms();
  104. // Execute the code every 2110ms
  105. FAST_2110ms() {
  106.  
  107. // Input from anti-theft sensor
  108. LowDigIn(2, Souliss_T4n_Alarm, ANTITHEFT);
  109.  
  110. // Execute the anti-theft logic
  111. Logic_T42(ANTITHEFT, 0xAB01);
  112.  
  113. // Build a watchdog chain to monitor the nodes
  114. mInput(ANTITHEFT) = Watchdog(0xAB01, WATCHDOG, Souliss_T4n_Alarm);
  115. }
  116. }
  117.  
  118. EXECUTESLOW() {
  119. UPDATESLOW();
  120.  
  121. SLOW_10s() {
  122. // Read temperature value from DHT sensor and convert from single-precision to half-precision
  123. float temperature = dht.readTemperature();
  124.  
  125. Souliss_ImportAnalog(memory_map, TEMPERATURE, &temperature);
  126. // Serial.print ("Temp ");
  127. // Serial.print (dht.readTemperature());
  128.  
  129. // Read humidity value from DHT sensor and convert from single-precision to half-precision
  130. float humidity = dht.readHumidity();
  131.  
  132. Souliss_ImportAnalog(memory_map, HUMIDITY, &humidity);
  133. // Serial.print (" & Hum ");
  134. // Serial.println (dht.readHumidity());
  135.  
  136.  
  137. }
  138. }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement