Guest User

Untitled

a guest
Mar 29th, 2018
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1. #include <ifx_dps310.h>
  2. #include <ESP8266WiFi.h>
  3. #include <BlynkSimpleEsp8266.h>
  4.  
  5. #define BLYNK_PRINT Serial
  6.  
  7. char auth[] = "YourAuthToken";
  8. // Your WiFi credentials.
  9. // Set password to "" for open networks.
  10. char ssid[] = "YourNetworkName";
  11. char pass[] = "YourPassword";
  12.  
  13. const unsigned char pressureLength = 50;
  14. unsigned char pressureCount = 0;
  15. long int pressure[pressureLength];
  16. unsigned char temperatureCount = 0;
  17. const unsigned char temperatureLength = 50;
  18. long int temperature[temperatureLength];
  19.  
  20. /*these thresholds will change according to where u currecntly are,
  21. these values worked perfetly in our coastal region where average temperatures were
  22. 34 degrees celsius
  23. */
  24. int pressureFallingThresh = 1;
  25. int pressureSleepingThresh = 4;
  26. int tempFeverThresh = 39;
  27. int pressureJogThresh = 5;
  28.  
  29. void setup()
  30. {
  31.   Serial.begin(9600);
  32.   Blynk.begin(auth, ssid, pass);
  33.   while (!Serial);
  34.   ifxDps310.begin(Wire);
  35.  
  36.   int ret = ifxDps310.setInterruptPolarity(1);
  37.   ret = ifxDps310.setInterruptSources(1, 0, 0);
  38.   //clear interrupt flag by reading
  39.   ifxDps310.getIntStatusFifoFull();
  40.  
  41.   int interruptPin = 3;
  42.   pinMode(interruptPin, INPUT);
  43.   attachInterrupt(digitalPinToInterrupt(interruptPin), onFifoFull, RISING);
  44.  
  45.   //start of a continuous measurement just like before
  46.   int temp_mr = 3;
  47.   int temp_osr = 2;
  48.   int prs_mr = 1;
  49.   int prs_osr = 3;
  50.   ret = ifxDps310.startMeasureBothCont(temp_mr, temp_osr, prs_mr, prs_osr);
  51.   if (ret != 0)
  52.   {
  53.     Serial.print("Init FAILED! ret = ");
  54.     Serial.println(ret);
  55.   }
  56.   else
  57.   {
  58.     Serial.println("Init complete!");
  59.   }
  60. }
  61.  
  62.  
  63. void loop()
  64. {
  65.   Blynk.run();
  66.  
  67.   Serial.println("loop running");
  68.   delay(500);
  69.  
  70.   if (pressureCount == pressureLength && temperatureCount == temperatureLength)
  71.   {
  72.     //print results
  73.     Serial.println();
  74.     Serial.println();
  75.     Serial.print(temperatureCount);
  76.     Serial.println(" temperature values found: ");
  77.     for (int i = 0; i < temperatureCount; i++)
  78.     {
  79.       Serial.print(temperature[i]);
  80.       if (temperature[i] > tempFeverThresh){
  81.         feverEmail();
  82.       }
  83.       Serial.println(" degrees of Celsius");
  84.     }
  85.     Serial.println();
  86.     Serial.print(pressureCount);
  87.     Serial.println(" pressure values found: ");
  88.     for (int i = 0; i < pressureCount; i++)
  89.     {
  90.       Serial.print(pressure[i]);
  91.       if (pressure[i] < pressureFallingThresh){
  92.         fallEmail();
  93.       }
  94.       else if (pressure[i] < pressureSleepingThresh && pressure[i] < pressureFallingThresh){
  95.         wakingUpEmail();
  96.       }
  97.       Serial.println(" Pascal");
  98.     }
  99.     Serial.println();
  100.     Serial.println();
  101.     //reset result counters
  102.     pressureCount = 0;
  103.     temperatureCount = 0;
  104.   }
  105.  
  106. }
  107.  
  108. void feverEmail()
  109. {
  110.   Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
  111.   Blynk.email("your_email@mail.com", "Subject: your patient has fever", "your patient has a fever and his/ her body temp is", temperature);
  112. }
  113.  
  114. void fallEmail()
  115. {
  116.   Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
  117.   Blynk.email("your_email@mail.com", "Subject: your patient just had a fall", "your patient just had a fall and requires assistance");
  118. }
  119.  
  120. void wakingUpEmail()
  121. {
  122.   Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
  123.   Blynk.email("your_email@mail.com", "Subject: your patient has just left his/her bed", "your patient has a just left the bed for unknown reasons, he/she needs assistance");
  124. }
  125.  
  126. //interrupt handler
  127. void onFifoFull()
  128. {
  129.   //message for debugging
  130.   Serial.println("Interrupt handler called");
  131.  
  132.   //clear interrupt flag by reading
  133.   ifxDps310.getIntStatusFifoFull();
  134.  
  135.   //calculate the number of free indexes in the result arrays
  136.   unsigned char prs_freespace = pressureLength - pressureCount;
  137.   unsigned char temp_freespace = temperatureLength - temperatureCount;
  138.   //read the results from Dps310, new results will be added at the end of the arrays
  139.   ifxDps310.getContResults(&temperature[temperatureCount], temp_freespace, &pressure[pressureCount], prs_freespace);
  140.   //after reading the result counters are increased by the amount of new results
  141.   pressureCount += prs_freespace;
  142.   temperatureCount += temp_freespace;
  143. }
Add Comment
Please, Sign In to add comment