Subhi Kalzie
Published © GPL3+

Smart Outlet

This project is about building a monitoring system using Hexabitz modules

IntermediateFull instructions provided3 hours190
Smart Outlet

Things used in this project

Story

Read more

Code

H23R0x.txt

C/C++
The Bluetooth module code
#include "BOS.h"




 uint8_t buffer;
volatile float I;
volatile float V;
float timeout=60000;
uint8_t MESGA[6] = {"\0"};
uint8_t MESGV[7] = {"\0"};


int main(void){

	Module_Init();		//Initialize Module &  BitzOS

	//Don't place your code here.
	for(;;){}
}



/* User Task */
void UserTask(void *argument)
{



	 BT_Set_Discoverable();

     AddBOSvar(FMT_FLOAT, (uint32_t)&V);
     AddBOSvar(FMT_FLOAT, (uint32_t)&I);

	 BT_Receive_Data((uint8_t *)&buffer,1);

	while(1)
	{



		 BT_Send_Data("label|",6);


		 sprintf(MESGA, "%.1f", I);
		 sprintf(MESGV, "%.2f\r\n", V);

		 BT_Send_Data((uint8_t*)MESGA,3);
		 BT_Send_Data("|",1);
		 BT_Send_Data((uint8_t*)MESGV,6);

		 Delay_ms(260);


		 if(buffer=='4')
		   {
			 if(I<11)
			 {
				  memcpy(&messageParams[0],&timeout,4);
			      SendMessageToModule(2,CODE_H0FRx_ON,4);
			 }
			    else  SendMessageToModule(2,CODE_H0FRx_OFF,0);

		   }
		   else if(buffer=='5')
		   {
		  	   	 SendMessageToModule(2,CODE_H0FRx_OFF,0);
		   }



		}

	}

H2AR3x.txt

C/C++
The H2AR3 code
 #include "BOS.h"

 #define max_v 180
 float volt,curr ,sum,sum_v,Ibuff[]={0},Vbuff[]={0};
 volatile float V,I;
 int j=0,i=0;


int main(void){

	Module_Init();


	for(;;){}
}



void UserTask(void *argument)
{

	   BOSMessaging.trace=TRACE_NONE;

	   AddBOSvar(FMT_FLOAT, (uint32_t)&V);
	   WriteRemote(3, (uint32_t) &V, 1, FMT_FLOAT,0);

	   AddBOSvar(FMT_FLOAT, (uint32_t)&I);
	   WriteRemote(3, (uint32_t) &I, 2, FMT_FLOAT,0);



	while(1)
	{

			   SampleV(&volt);

			   if(volt>max_v)     //Calculate Vrms
			      {
				   for(i=0;i<3;i++)
				   {
					   Vbuff[i]=volt;
					   sum_v+= Vbuff[i];
				   }

				   sum_v= sum_v/3;
			       sum_v= sum_v/1.414;

			      }
			          V=sum_v;
			          i=0;


			   WriteRemote(3, (uint32_t) &V, 1, FMT_FLOAT,0);
			   Delay_ms(20);


			   SampleA(&curr);

             if(j<3)     //Calculate Irms
               {
            	   Ibuff[j]=curr;
            	   sum+=pow(Ibuff[j],2);
            	   sum= sum/3;
            	   sum=sqrt(sum);

            	   j++;

               }
                   j=0;
                   I= sum;
                   Delay_ms(50);

			       WriteRemote(3, (uint32_t) & I, 2, FMT_FLOAT,0);
  	               Delay_ms(20);

	}
}

topology.txt

C/C++
topology.h
/*
 BitzOS (BOS) V0.2.6 - Copyright (C) 2017-2022 Hexabitz
 All rights reserved

 File Name     : topology.h
 Description   : Array topology definition.

 */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __topology_H
#define __topology_H
#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f0xx_hal.h"

#define __N	3					// Number of array modules

// Array modules
#define _mod1	1<<3
#define _mod2	2<<3
#define _mod3	3<<3
// Topology
static uint16_t array[__N ][7] ={
	{_H2AR3, 0,  0, _mod3 | P5, 0, 0, 0}, 						 // Module 1
	{_H0FR1,0, 0,0, _mod3 | P2, 0},	                        // Module 2
	{_H23R1, 0,_mod2 | P4, 0, 0, _mod1 | P3, 0},	               // Module 3
};

// Configurations for duplex serial ports
#if ( _module == 1 )
	#define	H2AR3	1
	#define	_P1pol_normal	1
	#define	_P2pol_normal	1
	#define	_P3pol_normal	1
	#define	_P4pol_normal	1
	#define	_P5pol_normal	1
	#define	_P6pol_normal	1
#endif

#if ( _module == 2 )
	#define	H0FR1	1
	#define	_P1pol_normal	1
	#define	_P2pol_normal	1
	#define	_P3pol_normal	1
	#define	_P4pol_reversed	1
	#define	_P5pol_normal	1
	#define	_P6pol_normal	1

#endif

#if ( _module ==3 )
	#define	H23R1	1
	#define	_P1pol_normal	1
	#define	_P2pol_normal	1
	#define	_P3pol_normal	1
	#define	_P4pol_normal	1
	#define	_P5pol_reversed	1
	#define	_P6pol_normal	1

#endif

#ifdef __cplusplus
}
#endif
#endif /*__ topology_H */

/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/

Credits

Subhi Kalzie

Subhi Kalzie

1 project • 0 followers

Comments