Development

» SCP v30 09 – Frame Class Utility

This is the basic code to create a frame with some Smart Cities Pro Sensor Board sensors

Required Materials

1 x Waspmote
1 x Battery
1 x Gases PRO board v30
1 x Temperature, Humidity and Pressure sensor BME280
1 x O3 Gas Sensor [Calibrated]
1 x NO2 Gas Sensor [Calibrated]
1 x Particle Matter Sensor

Notes

- Remember to connect the battery to Waspmote for proper operation.
- The connection of the sensor is described in the Smart Cities PRO technical guide.

Code

/*  
 *  ------------  [SCP_v30_09] - Frame Class Utility  -------------- 
 *  
 *  Explanation: This is the basic code to create a frame with some
 * 	Smart Cities Pro Sensor Board sensors
 *  
 *  Copyright (C) 2017 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify  
 *  it under the terms of the GNU General Public License as published by  
 *  the Free Software Foundation, either version 3 of the License, or  
 *  (at your option) any later version.  
 *   
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Version:		    3.1
 *  Design:             David Gascón
 *  Implementation:     Alejandro Gállego
 */

#include <WaspSensorCities_PRO.h>
#include <WaspSensorGas_Pro.h>
#include <WaspFrame.h>
#include <WaspOPC_N2.h>


Gas O3(SOCKET_B);
Gas NO2(SOCKET_C);

float temperature; 
float humidity; 
float pressure;

float concO3;
float concNO2;

int OPC_status;
int OPC_measure;

char node_ID[] = "Node_01";


void setup() 
{
	USB.ON();
	USB.println(F("Frame Utility Example for Gases Pro Sensor Board"));

	// Set the Waspmote ID
	frame.setID(node_ID); 
  
}

void loop()
{
	///////////////////////////////////////////
	// 1. Turn on sensors and wait
	///////////////////////////////////////////

	// Power on the sockets B and C for the gas sensor
	SensorCitiesPRO.ON(SOCKET_B);
	SensorCitiesPRO.ON(SOCKET_C);
	// Power on the socket E for the temperature sensor
	SensorCitiesPRO.ON(SOCKET_E);
	
	//Power on gas sensors
	O3.ON();
	NO2.ON();

	// Sensors need time to warm up and get a response from gas
	// To reduce the battery consumption, use deepSleep instead delay
	// After 2 minutes, Waspmote wakes up thanks to the RTC Alarm  
	PWR.deepSleep("00:00:02:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
	
	// Turn on the particle matter sensor
	OPC_status = OPC_N2.ON();
	if (OPC_status == 1)
	{
		USB.println(F("Particle sensor started"));

	}
	else
	{
		USB.println(F("Error starting the particle sensor"));
	}

	///////////////////////////////////////////
	// 2. Read sensors
	/////////////////////////////////////////// 
	// Read the sensors and compensate with the temperature internally
	concO3 = O3.getConc();
	concNO2 = NO2.getConc();

	// Read enviromental variables
	temperature = NO2.getTemp();
	humidity = NO2.getHumidity();
	pressure = NO2.getPressure();
	
	if (OPC_status == 1)
	{
		// Power the fan and the laser and perform a measure of 5 seconds
		OPC_measure = OPC_N2.getPM(5000,5000);
		if (OPC_measure == 1)
		{
			USB.println(F("Measure performed"));
			USB.print(F("PM 1: "));
			USB.print(OPC_N2._PM1);
			USB.println(F(" ug/m3"));
			USB.print(F("PM 2.5: "));
			USB.print(OPC_N2._PM2_5);
			USB.println(F(" ug/m3"));
			USB.print(F("PM 10: "));
			USB.print(OPC_N2._PM10);
			USB.println(F(" ug/m3"));

		}
		else
		{
			USB.print(F("Error performing the measure. Error code:"));
			USB.println(OPC_measure, DEC);
		}
	}

	///////////////////////////////////////////
	// 3. Turn off the sensors
	/////////////////////////////////////////// 

	//Power off sensors
	O3.OFF();
	NO2.OFF();
	
	SensorCitiesPRO.ON(SOCKET_B);
	SensorCitiesPRO.ON(SOCKET_C);
	SensorCitiesPRO.ON(SOCKET_E);
	
	OPC_N2.OFF();


	///////////////////////////////////////////
	// 4. Create ASCII frame
	/////////////////////////////////////////// 

	// Create new frame (ASCII)
	frame.createFrame(ASCII);

	// Add temperature
	frame.addSensor(SENSOR_CITIES_PRO_TC, temperature);
	// Add humidity
	frame.addSensor(SENSOR_CITIES_PRO_HUM, humidity);
	// Add pressure value
	frame.addSensor(SENSOR_CITIES_PRO_PRES, pressure);
	// Add O3 value
	frame.addSensor(SENSOR_CITIES_PRO_O3, concO3);
	// Add NO2 value
	frame.addSensor(SENSOR_CITIES_PRO_NO2, concNO2);
	// Add PM1 value
	frame.addSensor(SENSOR_CITIES_PRO_PM1, OPC_N2._PM1);
	// Add PM2.5 value
	frame.addSensor(SENSOR_CITIES_PRO_PM2_5, OPC_N2._PM2_5);
	// Add PM10 value
	frame.addSensor(SENSOR_CITIES_PRO_PM10, OPC_N2._PM10);

	// Show the frame
	frame.showFrame();

	
    ///////////////////////////////////////////
    // 4. Sleep
    /////////////////////////////////////////// 

    // Go to deepsleep	
    // After 30 seconds, Waspmote wakes up thanks to the RTC Alarm
    PWR.deepSleep("00:00:00:30", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
	
}

Output

H#
Frame Utility Example for Gases Pro Sensor Board
Particle sensor started
Measure performed
PM 1: 0.0700000000 ug/m3
PM 2.5: 0.0799999952 ug/m3
PM 10: 0.0799999952 ug/m3
===============================
Current ASCII Frame:
Length: 120
Frame Type: 134
frame (HEX): 3C3D3E86082330433430373836334439333734323446234E6F64655F303123302354433A32332E38372348554D3A34342E3223505245533A39393733392E3238234F333A302E333530234E4F323A372E36343823504D313A302E3037303023504D325F353A302E3038303023504D31303A302E3038303023
frame (STR): <=>�#0C407863D937424F#Node_01#0#TC:23.87#HUM:44.2#PRES:99739.28#O3:0.350#NO2:7.648#PM1:0.0700#PM2_5:0.0800#PM10:0.0800#
===============================
Particle sensor started
Measure performed
PM 1: 0.0799999952 ug/m3
PM 2.5: 0.0799999952 ug/m3
PM 10: 0.0799999952 ug/m3
===============================
Current ASCII Frame:
Length: 120
Frame Type: 134
frame (HEX): 3C3D3E86082330433430373836334439333734323446234E6F64655F303123312354433A32332E38372348554D3A34342E3223505245533A39393734332E3931234F333A302E323039234E4F323A322E30363823504D313A302E3038303023504D325F353A302E3038303023504D31303A302E3038303023
frame (STR): <=>�#0C407863D937424F#Node_01#1#TC:23.87#HUM:44.2#PRES:99743.91#O3:0.209#NO2:2.068#PM1:0.0800#PM2_5:0.0800#PM10:0.0800#
===============================
Particle sensor started
Measure performed
PM 1: 0.0700000000 ug/m3
PM 2.5: 0.0700000000 ug/m3
PM 10: 0.0700000000 ug/m3
===============================
Current ASCII Frame:
Length: 120
Frame Type: 134
frame (HEX): 3C3D3E86082330433430373836334439333734323446234E6F64655F303123322354433A32332E38362348554D3A34342E3323505245533A39393734332E3035234F333A302E313731234E4F323A312E35363423504D313A302E3037303023504D325F353A302E3037303023504D31303A302E3037303023
frame (STR): <=>�#0C407863D937424F#Node_01#2#TC:23.86#HUM:44.3#PRES:99743.05#O3:0.171#NO2:1.564#PM1:0.0700#PM2_5:0.0700#PM10:0.0700#
===============================
Particle sensor started
Measure performed
PM 1: 0.0700000000 ug/m3
PM 2.5: 0.0700000000 ug/m3
PM 10: 0.0700000000 ug/m3
===============================
Current ASCII Frame:
Length: 120
Frame Type: 134
frame (HEX): 3C3D3E86082330433430373836334439333734323446234E6F64655F303123332354433A32332E38362348554D3A34342E3123505245533A39393734332E3830234F333A302E313233234E4F323A312E33353423504D313A302E3037303023504D325F353A302E3037303023504D31303A302E3037303023
frame (STR): <=>�#0C407863D937424F#Node_01#3#TC:23.86#HUM:44.1#PRES:99743.80#O3:0.123#NO2:1.354#PM1:0.0700#PM2_5:0.0700#PM10:0.0700#
===============================
Particle sensor started
Measure performed
PM 1: 0.1100000023 ug/m3
PM 2.5: 0.1100000023 ug/m3
PM 10: 0.1100000023 ug/m3
===============================
Current ASCII Frame:
Length: 120
Frame Type: 134
frame (HEX): 3C3D3E86082330433430373836334439333734323446234E6F64655F303123342354433A32332E38392348554D3A34342E3323505245533A39393732352E3833234F333A302E313031234E4F323A312E35303523504D313A302E3131303023504D325F353A302E3131303023504D31303A302E3131303023
frame (STR): <=>�#0C407863D937424F#Node_01#4#TC:23.89#HUM:44.3#PRES:99725.83#O3:0.101#NO2:1.505#PM1:0.1100#PM2_5:0.1100#PM10:0.1100#
===============================

Quick Publish:

This site uses cookies. By clicking the “Accept” button you are agreeing to our use of cookies. Read More