--- /dev/null
+###########################################################################
+#
+# Copyright 2017 Samsung Electronics All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+# either express or implied. See the License for the specific
+# language governing permissions and limitations under the License.
+#
+###########################################################################
+############################################################################
+# apps/examples/sensor_test/Makefile
+#
+# Copyright (C) 2008, 2010-2013 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <gnutt@nuttx.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# 3. Neither the name NuttX nor the names of its contributors may be
+# used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+############################################################################
+
+-include $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+# sensor_test built-in application info
+
+APPNAME_LIST = ppd42ns
+THREADEXEC = TASH_EXECMD_ASYNC
+
+#########################
+# function definition
+#########################
+define ADD_SENSOR_SRCS
+ifeq ($(CONFIG_EXAMPLES_SENSOR_TEST_$(strip $(2))),y)
+CSRCS += $(strip $(1))_test.c
+endif
+endef
+
+define BDAT_PATH
+$(BUILTIN_REGISTRY)$(DELIM)$(strip $(1))_main.bdat
+endef
+
+define MAKE_BDAT
+ifeq ($(CONFIG_EXAMPLES_SENSOR_TEST_$(strip $(2))),y)
+$(call BDAT_PATH,$(1)): $(DEPCONFIG) Makefile
+ $(call REGISTER,sensor_$(strip $(1)),$(strip $(1))_test_main,$(THREADEXEC))
+else
+$(call BDAT_PATH,$(1)):
+endif
+endef
+#########################
+
+# sensor_test Example
+
+ASRCS =
+CSRCS =
+CXXSRCS =
+MAINSRC =
+
+# add sensor source files
+$(foreach APPNAME, $(APPNAME_LIST), \
+ $(eval $(call ADD_SENSOR_SRCS, $(APPNAME), $(shell echo $(strip $(APPNAME)) | tr a-z A-Z))))
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+CXXOBJS = $(CXXSRCS:.cpp=$(OBJEXT))
+MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
+OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)
+
+ifneq ($(CONFIG_BUILD_KERNEL),y)
+ OBJS += $(MAINOBJ)
+endif
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
+ifeq ($(WINTOOL),y)
+ BIN = ..\\..\\libapps$(LIBEXT)
+else
+ BIN = ../../libapps$(LIBEXT)
+endif
+endif
+
+ifeq ($(WINTOOL),y)
+ INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
+else
+ INSTALL_DIR = $(BIN_DIR)
+endif
+
+CONFIG_EXAMPLES_SELECT_TEST_PROGNAME ?= sensor_test$(EXEEXT)
+PROGNAME = $(CONFIG_EXAMPLES_SENSOR_TEST_PROGNAME)
+
+ROOTDEPPATH = --dep-path .
+
+# Common build
+
+VPATH =
+
+all: .built
+.PHONY: clean depend distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+$(CXXOBJS): %$(OBJEXT): %.cpp
+ $(call COMPILEXX, $<, $@)
+
+.built: $(OBJS)
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ @touch .built
+
+ifeq ($(CONFIG_BUILD_KERNEL),y)
+$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
+ @echo "LD: $(PROGNAME)"
+ $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
+ $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
+
+install: $(BIN_DIR)$(DELIM)$(PROGNAME)
+
+else
+install:
+
+endif
+
+ifeq ($(CONFIG_BUILTIN_APPS)$(CONFIG_EXAMPLES_SENSOR_TEST),yy)
+$(foreach APPNAME, $(APPNAME_LIST), \
+ $(eval $(call MAKE_BDAT, $(APPNAME), $(shell echo $(strip $(APPNAME)) | tr a-z A-Z))))
+
+context: $(foreach APPNAME, $(APPNAME_LIST), $(call BDAT_PATH, $(APPNAME)))
+
+else
+context:
+
+endif
+
+.depend: Makefile $(SRCS)
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @touch $@
+
+depend: .depend
+
+clean:
+ $(call DELFILE, .built)
+ $(call CLEAN)
+
+distclean: clean
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+
+-include Make.dep
+.PHONY: preconfig
+preconfig:
--- /dev/null
+/****************************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ ****************************************************************************/
+/**
+ * @file ppd42ns_test.c
+ * @brief the program for testing ppd42ns dust sensor
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <tinyara/config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <tinyara/sensors/sensor.h>
+#include <tinyara/sensors/ppd42ns.h>
+
+#define SUPPORT_MQTT_TRANSMISSION 0
+
+#if SUPPORT_MQTT_TRANSMISSION==1
+/**************
+ * Definitions
+ **************/
+#define MQTT_BROKER_IP_ADDRESS "192.168.1.14"
+#define MQTT_BROKER_PORT "1883"
+#define MQTT_TOPIC "/test/sensor"
+
+/**************
+ * Structure
+ **************/
+struct mqtt_pub_input {
+ int argc;
+ char **argv;
+};
+
+/**************
+ * Private Data
+ **************/
+char argv_buf[30][100];
+char *argv_cur[30];
+
+/******************
+ * function prototype
+ ******************/
+void create_arg(struct mqtt_pub_input *arg, char **argv_cur, char(*argv)[100], char *cmd);
+int mqtt_client_pub_main(int argc, char *argv[]);
+
+/******************
+ * static function
+ ******************/
+static int send_sensor_data(char *data)
+{
+ struct mqtt_pub_input arg;
+ char mqtt_str[128];
+
+ snprintf(mqtt_str, 128, "mqtt_pub -h %s -t %s -p %s -m %s", MQTT_BROKER_IP_ADDRESS, MQTT_TOPIC, MQTT_BROKER_PORT, data);
+
+ create_arg(&arg, argv_cur, argv_buf, mqtt_str);
+ mqtt_client_pub_cb(&arg);
+
+ return 0;
+}
+#endif /* SUPPORT_MQTT_TRANSMISSION */
+
+/****************************************************************************
+ * main
+ ****************************************************************************/
+
+#ifdef CONFIG_BUILD_KERNEL
+int main(int argc, FAR char *argv[])
+#else
+int ppd42ns_test_main(int argc, char *argv[])
+#endif
+{
+ int result = -1;
+
+ sensor_data_t data;
+ sensor_device_t *dust;
+ sensor_ioctl_value_t val;
+ char msg[64];
+ int sampling_interval_ms;
+ int test_cnt;
+ int loop_cnt;
+
+ if (argc != 3) {
+ printf("USAGE: sensor_ppd42ns [sampling_interval_in_ms] [loop_count] \n");
+ goto done_without_init;
+ }
+ sampling_interval_ms = atoi(argv[1]);
+ test_cnt = atoi(argv[2]);
+ loop_cnt = test_cnt;
+
+ dust = SENSOR_GET_HANDLE(SENSOR_NAME_PPD42NS);
+ if (dust == NULL) {
+ printf("ERROR: dust sensor handle is NULL.\n");
+ goto done_without_init;
+ }
+
+ SENSOR_INIT(dust);
+
+ printf(">>> Start \"%s\" dust sensor test\n", SENSOR_GET_NAME_STRING(SENSOR_NAME_PPD42NS));
+ printf(" - interval: %d ms\n", sampling_interval_ms);
+ printf(" - loop_count: %d\n", loop_cnt);
+ printf(" - mqtt transmission: ");
+#if SUPPORT_MQTT_TRANSMISSION==1
+ printf("ON\n");
+#else
+ printf("OFF\n");
+#endif
+ printf(" - sensor type: %d\n", SENSOR_GET_DEVICE_TYPE(dust));
+ if (SENSOR_IOCTL(dust, PPD42NS_IOCTL_ID_GET_GPIO_DEVPATH, &val) != 0) {
+ printf("ERROR: SENSOR_IOCTL() failed.\n");
+ goto done;
+ }
+ printf(" - sensor gpio devpath: %s\n", val.p_str);
+
+ SENSOR_ACTIVATE(dust);
+ while (loop_cnt) {
+ usleep(sampling_interval_ms * 1000);
+
+ if (SENSOR_GET_DATA(dust, &data) == 0) {
+ /* make sensor data message with json style */
+ sprintf(msg, "{\"dust\":%.2f}", data.fval);
+ printf("[%d] %s \n", (test_cnt - loop_cnt + 1), msg);
+
+#if SUPPORT_MQTT_TRANSMISSION==1
+ send_sensor_data(msg);
+#endif
+ }
+
+ loop_cnt--;
+ }
+ SENSOR_DEACTIVATE(dust);
+ printf("<<< End \"%s\" dust sensor test\n", SENSOR_GET_NAME_STRING(SENSOR_NAME_PPD42NS));
+
+ result = 0;
+
+done:
+ SENSOR_DEINIT(dust);
+
+done_without_init:
+ return result;
+}