Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Ashok R
Published

IoT HexSense

Sensing node for home automation.

IntermediateFull instructions providedOver 3 days2,472

Things used in this project

Hardware components

Hexiwear
NXP Hexiwear
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
LED (generic)
LED (generic)
×2

Software apps and online services

ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Iot Hexsense - Schematic

Code

Iot Hexsense - Code

C/C++
Add this code to MK64 Project
#include "main.h"

volatile uint8_t cloud_field1 = false;
volatile uint8_t cloud_field2 = false;
volatile uint8_t cloud_field3 = false;
volatile uint8_t cloud_connected = false;

uint8_t cloud_rx_enable = false;
volatile uint8_t cloud_field4[8]="00.00 C";
volatile uint8_t cloud_field5[8]="00.00 %";
volatile uint8_t cloud_field6[10]="00.00 kPa";

uint8_t cloud_rxbuffer[255];


osa_status_t CloudHostInterface_RxTaskDestroy();
osa_status_t CloudHostInterface_RxTaskCreate();
void CloudHostInterface_RxTask();
static CopyArray(uint8_t * src, uint8_t * des, uint8_t len);

void main()
{
  /** initialize the hardware */
  PE_low_level_init();

  /** disable write buffering end enable ARM exceptions */
  HEXIWEAR_EnableExceptions();

  /** initialize the startup task */
  HEXIWEAR_Init();

  /** start RTOS scheduler */
  HEXIWEAR_Start();



  while (1) {}
}




const gpio_output_pin_user_config_t Control_cfg[] = {
  {
    .pinName = Field2,
    .config.outputLogic = 0,
    .config.slewRate = kPortSlowSlewRate,
    .config.isOpenDrainEnabled = false,
    .config.driveStrength = kPortHighDriveStrength,
  },
  {
    .pinName = Field3,
    .config.outputLogic = 0,
    .config.slewRate = kPortSlowSlewRate,
    .config.isOpenDrainEnabled = false,
    .config.driveStrength = kPortHighDriveStrength,
  }

};


  Field2   = GPIO_MAKE_PIN(GPIOD_IDX, 8U);
  
  Field3   = GPIO_MAKE_PIN(GPIOD_IDX, 9U);
  
  
  
  
  
  
  
  
  
  
  /**
 * initialize RX tasks and queues
 * @return  task initialization status
 */
osa_status_t CloudHostInterface_RxTaskCreate()
{
  osa_status_t
    status;

  status = OSA_TaskCreate (
   	                            CloudHostInterface_RxTask,
   	                            (uint8_t*)"HostInterface_RxTask",
   	                            cloudHostInterfaceRxTaskStackSize_c,
   	                            NULL,
   								cloudHostInterfaceRxPriority_c,
   	                            (task_param_t)NULL,
   	                            false,
   	                            &cloud_rx_taskHandler
   	                          );


  return (osa_status_t)status;
}

osa_status_t CloudHostInterface_RxTaskDestroy()
{

	osa_status_t
	        status = OSA_TaskDestroy( cloud_rx_taskHandler );

	    if ( kStatus_OSA_Success != status )
	    {
	        catch( CATCH_INIT );
	    }


	    return (osa_status_t)status;

}



void CloudHostInterface_RxTask(){

	uint8_t remainingbytes=0;
	volatile uint32_t rxTimes = 0;
	uint8_t i;
	while(rxTimes==0){


		        UART_DRV_ReceiveData(HEXIWEAR_DEBUG_UART_INSTANCE, cloud_rxbuffer, 200u);

		// Wait until we receive a character
			   while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(HEXIWEAR_DEBUG_UART_INSTANCE,&remainingbytes)){


				   OSA_TaskYield();
			   }


			   rxTimes++;

	}

	cloud_connected = false;

	cloud_CreateTasks();

	for(i=0;i<200;i++){

		if((cloud_rxbuffer[i] == 'f') && (cloud_rxbuffer[i+1] == 'i')&&  (cloud_rxbuffer[i+2] == 'e') && (cloud_rxbuffer[i+3] == 'l') && (cloud_rxbuffer[i+4] == 'd')){

			cloud_connected = true;

//http://122.166.198.246/cgi-bin/webproc
//"entry_id":3,"field1":"001","field2":null,"field3":null,"field4":null,"field5":null,"field6":null,"field7":null,"field8":null}]}
			if(cloud_rxbuffer[i+5]=='2'){


				if(cloud_rxbuffer[i+9]=='1')
					cloud_field2 = true;
				else
					cloud_field2 = false;


			}

			if(cloud_rxbuffer[i+5]=='3'){

				if(cloud_rxbuffer[i+9]=='1')
					cloud_field3 = true;
				else
					cloud_field3 = false;


			}


		}



	}


	CloudHostInterface_RxTaskDestroy();




}

/**
 * create the app task
 * @param param optional parameter
 */
void cloud_CreateTasks( )
{
    osa_status_t
        status = OSA_TaskCreate (
        						  update_CloudTask,
                                  (uint8_t *) "flashlight task",
                                  CLOUD_STACK_SIZE,
                                  NULL,
                                  CLOUD_PRIO,
                                  (task_param_t)0,
                                  false,
                                  &cloud_write_taskHandler
                                );

    if ( kStatus_OSA_Success != status )
    {
        catch( CATCH_INIT );
    }
}




/**
 * create the app task
 * @param param optional parameter
 */
void cloud_read_CreateTasks( )
{
    osa_status_t
        status = OSA_TaskCreate (
        						  read_CloudTask,
                                  (uint8_t *) "flashlight task",
                                  CLOUD_STACK_SIZE,
                                  NULL,
                                  6,
                                  (task_param_t)0,
                                  false,
                                  &cloud_read_taskHandler
                                );

    if ( kStatus_OSA_Success != status )
    {
        catch( CATCH_INIT );
    }
}


/**
 * destroy the app task
 * @param param optional parameter
 */
void cloud_DestroyTasks( )
{
    osa_status_t
        status = OSA_TaskDestroy( cloud_write_taskHandler );

    if ( kStatus_OSA_Success != status )
    {
        catch( CATCH_INIT );
    }


}


/**
 * destroy the app task
 * @param param optional parameter
 */
void cloud_read_DestroyTasks( )
{
    osa_status_t
        status = OSA_TaskDestroy( cloud_read_taskHandler );

    if ( kStatus_OSA_Success != status )
    {
        catch( CATCH_INIT );
    }


}

static CopyArray(uint8_t *src, uint8_t *des, uint8_t len){

	while(len){

		*des++ = *src++;
		len--;

	};

Credits

Ashok R

Ashok R

37 projects • 102 followers
Hobbyist/Engineer/Director/Animatior

Comments