Loom 4 v4.5
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Loading...
Searching...
No Matches
Loom_SDI12.h
1#pragma once
2#include <map>
3#include <vector>
4
5#include "Arduino.h"
6
7#include "Module.h"
8#include "Loom_Manager.h"
9
10
11#include <SDI12.h>
12
13#define RESPONSE_SIZE 50
14
15
21class Loom_SDI12 : public Module{
22 protected:
23
24
25 /* These should be called only by Manager.h */
26 void measure() override; // Generic Measure Call To Pull Sensor Data
27 void package() override; // Generic Package Call to Store Sensor Data
28 void power_down() override;
29 void power_up() override;
30
31 public:
32
33 Loom_SDI12(Manager& man, const int pinAddr = 11); // Loomified Constructor
34
35 Loom_SDI12(const int pinAddr = 11); // Standard Sensor Interaction Constructor
36
37 void initialize() override; // Initialize the sensor interface
38
39 /* The following methods are intended for manual usage, outside of the Loom framework*/
40
41 const char* getSensorInfo(char addr); // Get the info of the connected sensor
42 std::vector<char> getInUseAddresses(); // Get a list of the in use addresses
43
44 void sendCommand(char response[RESPONSE_SIZE], char addr, const char* command); // Sends the given command to the given sensor on the bus and returns the result
45 void requestSensorInfo(char response[RESPONSE_SIZE], char addr); // Request Information about the connected SDI12 sensor
46 void getData(char addr); // Get the data from the connected sensor
47 std::vector<char> scanAddressSpace(); // Scans over the SDI-12 address space and returns a list of in-use addresses
48
49 float getTemperature() { return sensorData[0]; }; // Temperature of the soil
50 float getDielectricPerm() { return sensorData[1]; }; // Dielectric Permittivity of the soil
51 float getConductivity() { return sensorData[2]; }; // Conductivity of the soil
52
53 private:
54 Manager* manInst; // Instance of the Manager
55
56 SDI12 sdiInterface; // SDI-12 Library Interface
57
58 int sensorTracker = 0; // If we have multiple SDI-12 sensors on one bus we need to distinguish them in the json so increment a counter per
59
60 float sensorData[3]; // Array of floats to store sensor data
61 std::vector<char> inUseAddresses; // List of address that have SDI_12 sensors connected
62
63 std::map<char, const char*> addressToType; // Maps an SDI12 device address to a device type
64
65 void readResponse(char response[RESPONSE_SIZE]); // Reads and returns the sensor's response to the command
66 bool checkActive(char addr); // Checks if the current address is actually being used
67
68};
Definition: Loom_SDI12.h:21
Definition: Loom_Manager.h:18
Definition: Module.h:30