Things used in this project

Schematics

Iot Hexsense - Schematic

Code

Iot Hexsense - CodeC/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

Img 20170312 083955 zntgodaplu
Ashok R

Artist/Hobbyist /Engineer

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Lighting control
Intermediate
  • 201
  • 4

Lighting control using the Cayenne Dashboard button and wall mount button.

AWS IoT Environment for Home Assistant
Intermediate
  • 1,378
  • 11

Work in progress

Home Assistant is an automation platform that can track and control all kinds of devices and automate actions, which fits well with AWS IoT.

Doorbell (Working Captive Portal Use Case)
Intermediate
  • 103
  • 2

Wi-Fi Example of dynamical switching between SoftAp & STA: makes a wireless Arduino device configurable via a web page (SoftAP mode).

Home Automation Using IoT
Intermediate
  • 195
  • 3

Work in progress

Connecting home appliances to the internet and controlling them from anywhere in the world.

Tic-Tac-Toe with Teensy
Intermediate
  • 651
  • 10

Play tic-tac-toe against the Teensy with a physical board and playing pieces.

Autonomous Plant (ESP8266 - Arduino)
Intermediate
  • 594
  • 4

Full instructions

Want to build system that takes care of a plant? Here's my first attempt. Using ESP8266, soil moisture and Sonoff grow light

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login