AM2302(DHT22) sensors support.
[public/netxms.git] / src / agent / subagents / rpi / rpi.cpp
1 /*
2 ** Raspberry Pi subagent
3 ** Copyright (C) 2013 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 **/
20
21 #include <nms_common.h>
22 #include <nms_agent.h>
23
24 /**
25 *
26 */
27 BOOL StartSensorCollector();
28 void StopSensorCollector();
29
30 /**
31 * Sensor data
32 */
33 extern float g_sensorData[];
34 extern time_t g_sensorUpdateTime;
35
36 /**
37 * Sensor reading
38 */
39 static LONG H_Sensors(const TCHAR *param, const TCHAR *arg, TCHAR *value)
40 {
41 LONG ret;
42 if (time(NULL) - g_sensorUpdateTime <= 60)
43 {
44 ret_int(value, (int)g_sensorData[(int)arg]);
45 ret = SYSINFO_RC_SUCCESS;
46 }
47 else
48 {
49 ret = SYSINFO_RC_ERROR;
50 }
51
52 return ret;
53 }
54
55 /**
56 * Startup handler
57 */
58 static BOOL SubagentInit(Config *config)
59 {
60 return StartSensorCollector();
61 }
62
63 /**
64 * Shutdown handler
65 */
66 static void SubagentShutdown()
67 {
68 StopSensorCollector();
69 }
70
71 /**
72 * Parameters
73 */
74 static NETXMS_SUBAGENT_PARAM m_parameters[] =
75 {
76 { _T("Sensors.Humidity"), H_Sensors, (TCHAR *)0, DCI_DT_INT, _T("Humidity") },
77 { _T("Sensors.Temperature"), H_Sensors, (TCHAR *)1, DCI_DT_INT, _T("Temperature") }
78 };
79
80 /**
81 * Subagent information
82 */
83 static NETXMS_SUBAGENT_INFO m_info =
84 {
85 NETXMS_SUBAGENT_INFO_MAGIC,
86 _T("RPI"), NETXMS_VERSION_STRING,
87 SubagentInit,
88 SubagentShutdown,
89 NULL, // command handler
90 sizeof(m_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
91 m_parameters,
92 0, NULL, // lists
93 0, NULL, // tables
94 0, NULL, // actions
95 0, NULL // push parameters
96 };
97
98 /**
99 * Entry point for NetXMS agent
100 */
101 DECLARE_SUBAGENT_ENTRY_POINT(RPI)
102 {
103 *ppInfo = &m_info;
104 return TRUE;
105 }