Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Sanket Kulkarni
Created February 23, 2019

SensorNet Device for Smart Cities in India

This submission shows an application which can be used in smart city, to save electricity in the best way possible.

18
SensorNet Device for Smart Cities in India

Things used in this project

Hardware components

Relay
10A / 250V AC
×1
Resistor 1k ohm
Resistor 1k ohm
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Rapid IoT Prototyping Kit
NXP Rapid IoT Prototyping Kit
×1

Story

Read more

Schematics

Street Light Control

Used to activate the relay to control AC Supply

Application structure

Application structure for Smart street light control

Android App for smart City Application

App structure to monitor the air quality and Light in lix and Street Light status.

Code

Street Light Control

C/C++
Code for Making the PTD7 pin, to trigger the relay and control street light.
#include "callbacks.h"

//HEADER START

//HEADER END

void ATMO_Setup() {

}


ATMO_Status_t Interval_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t Interval_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_INTERVAL_Handle_t intervalHandle;
    ATMO_INTERVAL_AddAbilityInterval(
		ATMO_PROPERTY(Interval, instance), 
		ATMO_ABILITY(Interval, interval), 
		ATMO_PROPERTY(Interval, time), 
		&intervalHandle
	);
	
	return ATMO_Status_Success;
	
}


ATMO_Status_t Interval_interval(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t TSL2572AmbientLight_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t TSL2572AmbientLight_setup(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_TSL2572_Config_t config;
	config.address = ATMO_PROPERTY(TSL2572AmbientLight, i2cAddress);
	config.i2cDriverInstance = ATMO_PROPERTY(TSL2572AmbientLight, i2cInstance);

	return ( ATMO_TSL2572_Init(&config) == ATMO_TSL2572_Status_Success ) ? ATMO_Status_Success : ATMO_Status_Fail;

}


ATMO_Status_t TSL2572AmbientLight_setEnabled(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_TSL2572_SetEnabled(true);
return ATMO_Status_Success;
}


ATMO_Status_t TSL2572AmbientLight_setDisabled(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_TSL2572_SetEnabled(false);
return ATMO_Status_Success;
}


ATMO_Status_t TSL2572AmbientLight_setEnabledDisabled(ATMO_Value_t *in, ATMO_Value_t *out) {
bool enabled = false;
ATMO_GetBool(in, &enabled);
ATMO_TSL2572_SetEnabled(enabled);
return ATMO_Status_Success;
}


ATMO_Status_t TSL2572AmbientLight_readAmbientLight(ATMO_Value_t *in, ATMO_Value_t *out) {
    float lightLux;
    if(ATMO_TSL2572_GetAmbientLight(&lightLux) != ATMO_TSL2572_Status_Success)
    {
        ATMO_CreateValueVoid(out);
        return ATMO_Status_Fail;
    }
    ATMO_CreateValueInt(out, (int)lightLux);
    return ATMO_Status_Success;
}


ATMO_Status_t LightCompare_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t LightCompare_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t LightCompare_evaluate(ATMO_Value_t *in, ATMO_Value_t *out) {

	bool conditionTrue = false;

	// Convert property to same type as input
	ATMO_Value_t targetStr;
	ATMO_Value_t targetNum;
	
	ATMO_InitValue(&targetStr);
	ATMO_InitValue(&targetNum);
	ATMO_CreateValueString(&targetStr, ATMO_PROPERTY(LightCompare, target));
	ATMO_CreateValueConverted(&targetNum, in->type, &targetStr);
	
	if(ATMO_CompareValues(in, &targetNum, ATMO_PROPERTY(LightCompare, condition), &conditionTrue) != ATMO_Status_Success)
	{
		ATMO_Value_t value;
		ATMO_InitValue(&value);
		ATMO_TriggerHandler(ATMO_TRIGGER(LightCompare, invalidType), NULL);
		ATMO_FreeValue(&value);
		ATMO_FreeValue(&targetStr);
		ATMO_FreeValue(&targetNum);
		return ATMO_Status_Fail;
	}

	ATMO_FreeValue(&targetStr);
	ATMO_FreeValue(&targetNum);

	if(conditionTrue)
	{
		ATMO_Value_t value;
		ATMO_InitValue(&value);
		ATMO_TriggerHandler(ATMO_TRIGGER(LightCompare, conditionTrue), NULL);
		ATMO_FreeValue(&value);		
	}
	else
	{
		ATMO_Value_t value;
		ATMO_InitValue(&value);
		ATMO_TriggerHandler(ATMO_TRIGGER(LightCompare, conditionFalse), NULL);
		ATMO_FreeValue(&value);			
	}

	return ATMO_Status_Success;
	
}


ATMO_Status_t RelayClick_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_setup(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_Config_t config;
config.relay1Pin = ATMO_PROPERTY(RelayClick, relay1Pin);
config.relay2Pin = ATMO_PROPERTY(RelayClick, relay2Pin);
config.gpioDriverInstance = ATMO_PROPERTY(RelayClick, gpioDriverInstance);
ATMO_RELAYCLICK_Init(&ATMO_VARIABLE(RelayClick, handle), &config);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_setRelay1On(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_SetRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_ONE, true);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_setRelay2On(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_SetRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_TWO, true);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_setRelay1Off(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_SetRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_ONE, false);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_setRelay2Off(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_SetRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_TWO, false);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_toggleRelay1(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_ToggleRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_ONE);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_toggleRelay2(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_ToggleRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_TWO);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_setBothRelaysOn(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_SetRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_ONE, true);
ATMO_RELAYCLICK_SetRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_TWO, true);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_setBothRelaysOff(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_SetRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_ONE, false);
ATMO_RELAYCLICK_SetRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_TWO, false);
return ATMO_Status_Success;
}


ATMO_Status_t RelayClick_toggleBothRelays(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_RELAYCLICK_ToggleRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_ONE);
ATMO_RELAYCLICK_ToggleRelay(ATMO_VARIABLE(RelayClick, handle), RELAY_TWO);
return ATMO_Status_Success;
}


ATMO_Status_t CCS811AirQuality_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t CCS811AirQuality_setup(ATMO_Value_t *in, ATMO_Value_t *out) {
	ATMO_CCS811_Config_t config;
	config.operatingMode = ATMO_PROPERTY(CCS811AirQuality, operatingMode);
	config.address = ATMO_PROPERTY(CCS811AirQuality, i2cAddress);
	config.i2cDriverInstance = ATMO_PROPERTY(CCS811AirQuality, i2cInstance);

	return ( ATMO_CCS811_Init(&config) == ATMO_CCS811_Status_Success ) ? ATMO_Status_Success : ATMO_Status_Fail;

}


ATMO_Status_t CCS811AirQuality_setEnabled(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_CCS811_SetEnabled(true);
return ATMO_Status_Success;
}


ATMO_Status_t CCS811AirQuality_setDisabled(ATMO_Value_t *in, ATMO_Value_t *out) {
ATMO_CCS811_SetEnabled(false);
return ATMO_Status_Success;
}


ATMO_Status_t CCS811AirQuality_setEnabledDisabled(ATMO_Value_t *in, ATMO_Value_t *out) {
bool enabled = false;
ATMO_GetBool(in, &enabled);
ATMO_CCS811_SetEnabled(enabled);
return ATMO_Status_Success;
}


ATMO_Status_t CCS811AirQuality_readTVOC(ATMO_Value_t *in, ATMO_Value_t *out) {
    uint16_t tvoc;

    if(ATMO_CCS811_GetTVOC(&tvoc) == ATMO_CCS811_Status_Success)
    {
        ATMO_CreateValueUnsignedInt(out, (unsigned int)tvoc);
    }
    else
    {
        ATMO_CreateValueVoid(out);
    }
    
    return ATMO_Status_Success;
}


ATMO_Status_t CCS811AirQuality_readCO2(ATMO_Value_t *in, ATMO_Value_t *out) {
    uint16_t co2;
    
    if(ATMO_CCS811_GetCO2(&co2) == ATMO_CCS811_Status_Success)
    {
        ATMO_CreateValueInt(out, (int)co2);
    }
    else
    {
        ATMO_CreateValueVoid(out);
    }
  
    return ATMO_Status_Success;
}


ATMO_Status_t EmbeddedNxpRpkBuzzer_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t EmbeddedNxpRpkBuzzer_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedNxpRpkBuzzer_beep(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_MK64F_Buzzer_On();
    ATMO_PLATFORM_DelayMilliseconds(200);
    ATMO_MK64F_Buzzer_Off();
	return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedNxpRpkBuzzer_turnOn(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_MK64F_Buzzer_On();
    ATMO_CreateValueBool(out, true);
	return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedNxpRpkBuzzer_turnOff(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_MK64F_Buzzer_Off();
    ATMO_CreateValueBool(out, false);
	return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedNxpRpkBuzzer_toggle(ATMO_Value_t *in, ATMO_Value_t *out) {

    bool newState = false;
    ATMO_MK64F_Buzzer_Toggle(&newState);
    ATMO_CreateValueBool(out, newState);
	return ATMO_Status_Success;
    
}


ATMO_Status_t EmbeddedNxpRpkBuzzer_setState(ATMO_Value_t *in, ATMO_Value_t *out) {

    bool on = false;
    ATMO_GetBool(in, &on);

    if( on )
    {
        ATMO_MK64F_Buzzer_On();
    }
    else
    {
        ATMO_MK64F_Buzzer_Off();
    }
    ATMO_CreateValueBool(out, on);
    
	return ATMO_Status_Success;
    
}


ATMO_Status_t GetLightValue_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t GetAirQualityStr_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t ShowLightVal_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t ShowLightVal_displayPage(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_DisplayPageByCoord(ATMO_PROPERTY(ShowLightVal, x), ATMO_PROPERTY(ShowLightVal, y), false);
	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowLightVal_onDisplayed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
    
}


ATMO_Status_t ShowLightVal_topRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowLightVal_bottomRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowLightVal_topLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowLightVal_bottomLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowLightVal_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_UI_PAGE_Config_t config;
	config.hidden = ATMO_PROPERTY(ShowLightVal, pageHidden);
	config.textColor = ATMO_PROPERTY(ShowLightVal, textColor);
    config.activeButtons = ATMO_UI_Page_GetButtonMask(ATMO_PROPERTY(ShowLightVal, topRightButtonEnabled),
    ATMO_PROPERTY(ShowLightVal,bottomRightButtonEnabled), ATMO_PROPERTY(ShowLightVal, topLeftButtonEnabled), ATMO_PROPERTY(ShowLightVal, bottomLeftButtonEnabled));
	config.x = ATMO_PROPERTY(ShowLightVal, x);
    config.x = ATMO_PROPERTY(ShowLightVal, x);
    config.y = ATMO_PROPERTY(ShowLightVal, y);
	strncpy(config.topLeftButtonLabel, ATMO_PROPERTY(ShowLightVal, topLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.topRightButtonLabel, ATMO_PROPERTY(ShowLightVal, topRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomLeftButtonLabel, ATMO_PROPERTY(ShowLightVal, bottomLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomRightButtonLabel, ATMO_PROPERTY(ShowLightVal, bottomRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
    config.spanX = ATMO_PROPERTY(ShowLightVal, spanX);
	config.spanY = ATMO_PROPERTY(ShowLightVal, spanY);
    config.title = ATMO_PROPERTY(ShowLightVal, pageTitle);
    config.titleHidden = ATMO_PROPERTY(ShowLightVal, titleHidden);
	ATMO_UI_SINGLEICONTEXT_Init(&config);
	ATMO_VARIABLE(ShowLightVal, pageHandle) = config.templateInstance;
    ATMO_UI_SINGLEICONTEXT_SetMainText(config.templateInstance, ATMO_PROPERTY(ShowLightVal, label));
    ATMO_UI_SINGLEICONTEXT_SetIcon(config.templateInstance, ATMO_PROPERTY(ShowLightVal, icon));
    ATMO_UI_SINGLEICONTEXT_RegisterOnDisplayedAbilityHandle(ATMO_VARIABLE(ShowLightVal,pageHandle), ATMO_ABILITY(ShowLightVal, onDisplayed));
    ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(ShowLightVal,pageHandle), 1, ATMO_ABILITY(ShowLightVal, topRightButtonPressed));
	ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(ShowLightVal,pageHandle), 2, ATMO_ABILITY(ShowLightVal, bottomRightButtonPressed));
	ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(ShowLightVal,pageHandle), 3, ATMO_ABILITY(ShowLightVal, topLeftButtonPressed));
    ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(ShowLightVal,pageHandle), 4, ATMO_ABILITY(ShowLightVal, bottomLeftButtonPressed));
    ATMO_UI_SINGLEICONTEXT_RegisterOnLeaveAbilityHandle(config.templateInstance, ATMO_ABILITY(ShowLightVal, onLeave));
	return ATMO_Status_Success;
    
}


ATMO_Status_t ShowLightVal_onLeave(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowLightVal_setLabel(ATMO_Value_t *in, ATMO_Value_t *out) {

    char label[32];
    if(ATMO_GetString(in, label, 32) == ATMO_Status_Success)
    {
        ATMO_UI_SINGLEICONTEXT_SetMainText(ATMO_VARIABLE(ShowLightVal,pageHandle), label);
    }
    else
    {
        return ATMO_Status_Fail;
    }

    return ATMO_Status_Success;
    
}


ATMO_Status_t ShowAirQuality_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t ShowAirQuality_displayPage(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_UI_Page_DisplayPageByCoord(ATMO_PROPERTY(ShowAirQuality, x), ATMO_PROPERTY(ShowAirQuality, y), false);
	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowAirQuality_onDisplayed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
    
}


ATMO_Status_t ShowAirQuality_topRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowAirQuality_bottomRightButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowAirQuality_topLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowAirQuality_bottomLeftButtonPressed(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowAirQuality_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

    ATMO_UI_PAGE_Config_t config;
	config.hidden = ATMO_PROPERTY(ShowAirQuality, pageHidden);
	config.textColor = ATMO_PROPERTY(ShowAirQuality, textColor);
    config.activeButtons = ATMO_UI_Page_GetButtonMask(ATMO_PROPERTY(ShowAirQuality, topRightButtonEnabled),
    ATMO_PROPERTY(ShowAirQuality,bottomRightButtonEnabled), ATMO_PROPERTY(ShowAirQuality, topLeftButtonEnabled), ATMO_PROPERTY(ShowAirQuality, bottomLeftButtonEnabled));
	config.x = ATMO_PROPERTY(ShowAirQuality, x);
    config.x = ATMO_PROPERTY(ShowAirQuality, x);
    config.y = ATMO_PROPERTY(ShowAirQuality, y);
	strncpy(config.topLeftButtonLabel, ATMO_PROPERTY(ShowAirQuality, topLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.topRightButtonLabel, ATMO_PROPERTY(ShowAirQuality, topRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomLeftButtonLabel, ATMO_PROPERTY(ShowAirQuality, bottomLeftButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
	strncpy(config.bottomRightButtonLabel, ATMO_PROPERTY(ShowAirQuality, bottomRightButtonLabel), ATMO_BUTTON_LABEL_MAXLEN);
    config.spanX = ATMO_PROPERTY(ShowAirQuality, spanX);
	config.spanY = ATMO_PROPERTY(ShowAirQuality, spanY);
    config.title = ATMO_PROPERTY(ShowAirQuality, pageTitle);
    config.titleHidden = ATMO_PROPERTY(ShowAirQuality, titleHidden);
	ATMO_UI_SINGLEICONTEXT_Init(&config);
	ATMO_VARIABLE(ShowAirQuality, pageHandle) = config.templateInstance;
    ATMO_UI_SINGLEICONTEXT_SetMainText(config.templateInstance, ATMO_PROPERTY(ShowAirQuality, label));
    ATMO_UI_SINGLEICONTEXT_SetIcon(config.templateInstance, ATMO_PROPERTY(ShowAirQuality, icon));
    ATMO_UI_SINGLEICONTEXT_RegisterOnDisplayedAbilityHandle(ATMO_VARIABLE(ShowAirQuality,pageHandle), ATMO_ABILITY(ShowAirQuality, onDisplayed));
    ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(ShowAirQuality,pageHandle), 1, ATMO_ABILITY(ShowAirQuality, topRightButtonPressed));
	ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(ShowAirQuality,pageHandle), 2, ATMO_ABILITY(ShowAirQuality, bottomRightButtonPressed));
	ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(ShowAirQuality,pageHandle), 3, ATMO_ABILITY(ShowAirQuality, topLeftButtonPressed));
    ATMO_UI_SINGLEICONTEXT_RegisterButtonAbilityHandle(ATMO_VARIABLE(ShowAirQuality,pageHandle), 4, ATMO_ABILITY(ShowAirQuality, bottomLeftButtonPressed));
    ATMO_UI_SINGLEICONTEXT_RegisterOnLeaveAbilityHandle(config.templateInstance, ATMO_ABILITY(ShowAirQuality, onLeave));
	return ATMO_Status_Success;
    
}


ATMO_Status_t ShowAirQuality_onLeave(ATMO_Value_t *in, ATMO_Value_t *out) {

	return ATMO_Status_Success;
	
}


ATMO_Status_t ShowAirQuality_setLabel(ATMO_Value_t *in, ATMO_Value_t *out) {

    char label[32];
    if(ATMO_GetString(in, label, 32) == ATMO_Status_Success)
    {
        ATMO_UI_SINGLEICONTEXT_SetMainText(ATMO_VARIABLE(ShowAirQuality,pageHandle), label);
    }
    else
    {
        return ATMO_Status_Fail;
    }

    return ATMO_Status_Success;
    
}


ATMO_Status_t LightCharacteristics_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t LightCharacteristics_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_BLE_GATTSAddService(
		ATMO_PROPERTY(LightCharacteristics, instance),
		&ATMO_VARIABLE(LightCharacteristics, bleServiceHandle), 
		ATMO_PROPERTY(LightCharacteristics, bleServiceUuid));
	
	uint8_t property = 0;
	uint8_t permission = 0;
	
	property |= ATMO_PROPERTY(LightCharacteristics, read) ? ATMO_BLE_Property_Read : 0;
	property |= ATMO_PROPERTY(LightCharacteristics, write) ? ATMO_BLE_Property_Write : 0;
	property |= ATMO_PROPERTY(LightCharacteristics, notify) ? ATMO_BLE_Property_Notify : 0;

	permission |= ATMO_PROPERTY(LightCharacteristics, read) ? ATMO_BLE_Permission_Read : 0;
	permission |= ATMO_PROPERTY(LightCharacteristics, write) ? ATMO_BLE_Permission_Write : 0;

	ATMO_DATATYPE types[3] = {ATMO_PROPERTY(LightCharacteristics, writeDataType), ATMO_PROPERTY(LightCharacteristics, readDataType), ATMO_PROPERTY(LightCharacteristics, notifyDataType)};
	
	ATMO_BLE_GATTSAddCharacteristic(
		ATMO_PROPERTY(LightCharacteristics, instance),
		&ATMO_VARIABLE(LightCharacteristics, bleCharacteristicHandle), 
		ATMO_VARIABLE(LightCharacteristics, bleServiceHandle), 
		ATMO_PROPERTY(LightCharacteristics, bleCharacteristicUuid), 
		property, permission, ATMO_GetMaxValueSize(3, 64, types));
	
	ATMO_BLE_GATTSRegisterCharacteristicAbilityHandle(
		ATMO_PROPERTY(LightCharacteristics, instance),
		ATMO_VARIABLE(LightCharacteristics, bleCharacteristicHandle), 
		ATMO_BLE_Characteristic_Written, 
		ATMO_ABILITY(LightCharacteristics, written));
	
	return ATMO_Status_Success;
	
}


ATMO_Status_t LightCharacteristics_setValue(ATMO_Value_t *in, ATMO_Value_t *out) {

	
	// Convert to the desired write data type
	ATMO_Value_t convertedValue;
	ATMO_InitValue(&convertedValue);
	ATMO_CreateValueConverted(&convertedValue, ATMO_PROPERTY(LightCharacteristics, readDataType), in);

	ATMO_BLE_GATTSSetCharacteristic(
		ATMO_PROPERTY(LightCharacteristics, instance),
		ATMO_VARIABLE(LightCharacteristics, bleCharacteristicHandle),
		convertedValue.size, 
		(uint8_t *)convertedValue.data,
		NULL);
	
	ATMO_FreeValue(&convertedValue);
		
	return ATMO_Status_Success;
	
}


ATMO_Status_t LightCharacteristics_written(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_CreateValueConverted(out, ATMO_PROPERTY(LightCharacteristics, writeDataType), in);
	return ATMO_Status_Success;
	
}


ATMO_Status_t LightCharacteristics_subscibed(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t LightCharacteristics_unsubscribed(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t AirQualityCharacteristics_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t AirQualityCharacteristics_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_BLE_GATTSAddService(
		ATMO_PROPERTY(AirQualityCharacteristics, instance),
		&ATMO_VARIABLE(AirQualityCharacteristics, bleServiceHandle), 
		ATMO_PROPERTY(AirQualityCharacteristics, bleServiceUuid));
	
	uint8_t property = 0;
	uint8_t permission = 0;
	
	property |= ATMO_PROPERTY(AirQualityCharacteristics, read) ? ATMO_BLE_Property_Read : 0;
	property |= ATMO_PROPERTY(AirQualityCharacteristics, write) ? ATMO_BLE_Property_Write : 0;
	property |= ATMO_PROPERTY(AirQualityCharacteristics, notify) ? ATMO_BLE_Property_Notify : 0;

	permission |= ATMO_PROPERTY(AirQualityCharacteristics, read) ? ATMO_BLE_Permission_Read : 0;
	permission |= ATMO_PROPERTY(AirQualityCharacteristics, write) ? ATMO_BLE_Permission_Write : 0;

	ATMO_DATATYPE types[3] = {ATMO_PROPERTY(AirQualityCharacteristics, writeDataType), ATMO_PROPERTY(AirQualityCharacteristics, readDataType), ATMO_PROPERTY(AirQualityCharacteristics, notifyDataType)};
	
	ATMO_BLE_GATTSAddCharacteristic(
		ATMO_PROPERTY(AirQualityCharacteristics, instance),
		&ATMO_VARIABLE(AirQualityCharacteristics, bleCharacteristicHandle), 
		ATMO_VARIABLE(AirQualityCharacteristics, bleServiceHandle), 
		ATMO_PROPERTY(AirQualityCharacteristics, bleCharacteristicUuid), 
		property, permission, ATMO_GetMaxValueSize(3, 64, types));
	
	ATMO_BLE_GATTSRegisterCharacteristicAbilityHandle(
		ATMO_PROPERTY(AirQualityCharacteristics, instance),
		ATMO_VARIABLE(AirQualityCharacteristics, bleCharacteristicHandle), 
		ATMO_BLE_Characteristic_Written, 
		ATMO_ABILITY(AirQualityCharacteristics, written));
	
	return ATMO_Status_Success;
	
}


ATMO_Status_t AirQualityCharacteristics_setValue(ATMO_Value_t *in, ATMO_Value_t *out) {

	
	// Convert to the desired write data type
	ATMO_Value_t convertedValue;
	ATMO_InitValue(&convertedValue);
	ATMO_CreateValueConverted(&convertedValue, ATMO_PROPERTY(AirQualityCharacteristics, readDataType), in);

	ATMO_BLE_GATTSSetCharacteristic(
		ATMO_PROPERTY(AirQualityCharacteristics, instance),
		ATMO_VARIABLE(AirQualityCharacteristics, bleCharacteristicHandle),
		convertedValue.size, 
		(uint8_t *)convertedValue.data,
		NULL);
	
	ATMO_FreeValue(&convertedValue);
		
	return ATMO_Status_Success;
	
}


ATMO_Status_t AirQualityCharacteristics_written(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_CreateValueConverted(out, ATMO_PROPERTY(AirQualityCharacteristics, writeDataType), in);
	return ATMO_Status_Success;
	
}


ATMO_Status_t AirQualityCharacteristics_subscibed(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t AirQualityCharacteristics_unsubscribed(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t LightStatus_trigger(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t LightStatus_setup(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_BLE_GATTSAddService(
		ATMO_PROPERTY(LightStatus, instance),
		&ATMO_VARIABLE(LightStatus, bleServiceHandle), 
		ATMO_PROPERTY(LightStatus, bleServiceUuid));
	
	uint8_t property = 0;
	uint8_t permission = 0;
	
	property |= ATMO_PROPERTY(LightStatus, read) ? ATMO_BLE_Property_Read : 0;
	property |= ATMO_PROPERTY(LightStatus, write) ? ATMO_BLE_Property_Write : 0;
	property |= ATMO_PROPERTY(LightStatus, notify) ? ATMO_BLE_Property_Notify : 0;

	permission |= ATMO_PROPERTY(LightStatus, read) ? ATMO_BLE_Permission_Read : 0;
	permission |= ATMO_PROPERTY(LightStatus, write) ? ATMO_BLE_Permission_Write : 0;

	ATMO_DATATYPE types[3] = {ATMO_PROPERTY(LightStatus, writeDataType), ATMO_PROPERTY(LightStatus, readDataType), ATMO_PROPERTY(LightStatus, notifyDataType)};
	
	ATMO_BLE_GATTSAddCharacteristic(
		ATMO_PROPERTY(LightStatus, instance),
		&ATMO_VARIABLE(LightStatus, bleCharacteristicHandle), 
		ATMO_VARIABLE(LightStatus, bleServiceHandle), 
		ATMO_PROPERTY(LightStatus, bleCharacteristicUuid), 
		property, permission, ATMO_GetMaxValueSize(3, 64, types));
	
	ATMO_BLE_GATTSRegisterCharacteristicAbilityHandle(
		ATMO_PROPERTY(LightStatus, instance),
		ATMO_VARIABLE(LightStatus, bleCharacteristicHandle), 
		ATMO_BLE_Characteristic_Written, 
		ATMO_ABILITY(LightStatus, written));
	
	return ATMO_Status_Success;
	
}


ATMO_Status_t LightStatus_setValue(ATMO_Value_t *in, ATMO_Value_t *out) {

	
	// Convert to the desired write data type
	ATMO_Value_t convertedValue;
	ATMO_InitValue(&convertedValue);
	ATMO_CreateValueConverted(&convertedValue, ATMO_PROPERTY(LightStatus, readDataType), in);

	ATMO_BLE_GATTSSetCharacteristic(
		ATMO_PROPERTY(LightStatus, instance),
		ATMO_VARIABLE(LightStatus, bleCharacteristicHandle),
		convertedValue.size, 
		(uint8_t *)convertedValue.data,
		NULL);
	
	ATMO_FreeValue(&convertedValue);
		
	return ATMO_Status_Success;
	
}


ATMO_Status_t LightStatus_written(ATMO_Value_t *in, ATMO_Value_t *out) {

	ATMO_CreateValueConverted(out, ATMO_PROPERTY(LightStatus, writeDataType), in);
	return ATMO_Status_Success;
	
}


ATMO_Status_t LightStatus_subscibed(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}


ATMO_Status_t LightStatus_unsubscribed(ATMO_Value_t *in, ATMO_Value_t *out) {
	return ATMO_Status_Success;
}

//FOOTER START

//FOOTER END

Credits

Sanket Kulkarni

Sanket Kulkarni

4 projects • 0 followers
Almost 4 years of Experience in Firmware developement. Aspiring to become a Industry 4.0 and Firmware and Hardware Expert.

Comments