A low cost DIY sound pressure level sensor for enabling environmental noise awareness. https://lukasschwarz.org/noise-sensor
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

92 righe
2.2 KiB

  1. // vim: noai:sw=2:tw=88
  2. #include <Wire.h>
  3. #include "NoiseSensorNode.h"
  4. #include <WiFiUdp.h>
  5. #define LORA_HEADER_LENGTH 2
  6. #define BATTERY_FIELD_SIZE 1
  7. #define PACKET_COUNT 5
  8. class NoiseSensorClass {
  9. private:
  10. //NTPClient* _time_client;
  11. uint32_t _last_sync_time;
  12. uint8_t _tick_count = 20;
  13. uint8_t _tick_duration = 2; // in seconds
  14. uint8_t _tx_offset = 1;
  15. uint8_t _i2c_address = 0x3C;
  16. bool _first_sync = true;
  17. // These aren't _real_ const but they shouldn't be redefined nonetheless.
  18. uint16_t _PACKET_SIZE;
  19. uint16_t _REQUEST_SIZE;
  20. NoiseSensorNode* _nodes[];
  21. uint8_t getDeviceID();
  22. bool setupNTPClient();
  23. uint32_t getEpoch();
  24. public:
  25. /**
  26. * Begin the measurement cycle by sending a sync message.
  27. *
  28. * @return true on success, false on failure
  29. */
  30. bool begin();
  31. /**
  32. * Call begin() with a custom tick count.
  33. *
  34. * @return true on success, false on failure
  35. */
  36. bool begin(uint8_t tick_count);
  37. /**
  38. * Call begin() with a custom tick count and tick duration.
  39. *
  40. * @return true on success, false on failure
  41. */
  42. bool begin(uint8_t tick_count, uint8_t tick_duration);
  43. /**
  44. * Call begin() with a custom tick count, tick duration and tx_offset.
  45. *
  46. * @return true on success, false on failure
  47. */
  48. bool begin(uint8_t tick_count, uint8_t tick_duration, uint8_t tx_offset);
  49. void setIds(const char* sensebox_ids[], const char* sensor_ids[]);
  50. String buildHTTPHeader(uint8_t device_id, const char* server, uint16_t content_length);
  51. bool beaconReady();
  52. bool requestReady();
  53. /**
  54. * Read the newly available data from the slave.
  55. *
  56. * @return true on success, false on failure
  57. */
  58. bool read();
  59. /**
  60. * Print the measurements in a pretty format.
  61. */
  62. void printMeasurements(uint8_t device_id);
  63. /**
  64. * Send the sync message to the slave.
  65. *
  66. * @return true on success, false on failure
  67. */
  68. bool sendSyncBeacon();
  69. String buildSenseBoxJSON(uint8_t device_id);
  70. };
  71. extern NoiseSensorClass NoiseSensor;