Пример #1
0
void FlyportTask()
{	
	vTaskDelay(100);
	UARTWrite(1,"Welcome to GROVE NEST example!\r\n");

	// GROVE board
	void *board = new(GroveNest);
	
	void *tempAn = new(An_Temp);
 
	// Attach devices
	attachToBoard(board, tempAn, AN1);
 
	float anVal = 0.0;
	char mess[50];
	char msg[50];
	
	// Connection to Network
	#if defined (FLYPORT_WF)
	WFConnect(WF_DEFAULT);
	while (WFStatus != CONNECTED);
	#endif
	#if defined (FLYPORTETH)
	while(!MACLinked);
	#endif
	UARTWrite(1,"Flyport connected... hello world!\r\n");
	vTaskDelay(200);
	
	
	while(1)
	{
		postSensorValue("temperature", (double)(get(tempAn)), "1377515972748279ff7a4b8ee4b27ba6f6db0412227ba");
		
		vTaskDelay(6000);
	}
}
Пример #2
0
void FlyportTask()
{
	void *board = new(Board,GROVE1);
	
	void *rgb1 = new(Rgb,2);
	void *rgb2 = new(Rgb,2);
	void *rgb3 = new(Rgb,2);

	attachSensorToBoard(board,rgb1,PORT1);
	attachSensorToBoard(board,rgb2,PORT2);
	attachSensorToBoard(board,rgb3,PORT3);
	
	set(rgb1,OFF);
	set(rgb2,OFF);
	set(rgb3,OFF);
			
    WFConnect(WF_DEFAULT);
	while (WFStatus != CONNECTED);
	UARTWrite(1,"Flyport connected.\r\n");
	
	while(1)
	{
		switch(status) 
		{
			case SLEEPER:
				if(prevstatus!=(int)status)
				{ 
					prevstatus = status;
					UARTWrite(1,"Mood:: Sleeper!\r\n");
					set(rgb1,OFF);
					set(rgb2,OFF);
					set(rgb3,OFF);
				}
				break;
			case SLACKER:
				if(prevstatus!=(int)status)
				{ 
					prevstatus = status;
					UARTWrite(1,"Mood:: Slacker!\r\n");
				}
				slackerLeds(rgb1, rgb2, rgb3);
				vTaskDelay(1);
				break;
			case ROCKER:
				if(prevstatus!=(int)status)
				{ 
					prevstatus = status;
					UARTWrite(1,"Mood:: Rocker!\r\n");
				}
				rockerLeds(rgb1, rgb2, rgb3);
				vTaskDelay(5);
				break;
			case HACKER:
				if(prevstatus!=(int)status)
				{ 
					prevstatus = status;
					UARTWrite(1,"Mood:: Hacker!\r\n");
				}
				hackerLeds(rgb1, rgb2, rgb3);
				vTaskDelay(10);
				break;
		}
	}
}
//void opt_handle_time()
void optimization()
{
	UARTWrite(1,"Optimization Mode Enabled");
	opt_trig=0;
	on_flag=0;
	off_flag=0;
	if(profile.OnType==MOTION) //intializing motion triggered interrupt
	{
		//IOInit(PIR_PORT,inup);
		IOInit(PIR_PORT, EXT_INT2);
		INTInit(2, external_interrupt_function, 0);
		INTEnable(2);	
	}
	alarmflag_opt = 0;
	while(1)
	{
		
		if(on_flag==1)
		{
			on_flag=0;
			opt_trig=0;
			sprintf(input,"\nLast Wifi Status : %d\n\n",WFStatus);
			UARTWrite(1,input);
			UARTWrite(1,"Wi-Fi transceiver activation...\r\n");
			WFOn();
			while (WFStatus == TURNED_OFF);
			UARTWrite(1,"Wi-Fi On\r\n");
			//to check if Custom profile exists then load it or otherwise load the default profile after turning on wif
				if(NETCustomExist())
				{
					WFConnect(WF_CUSTOM);
				}
				else
				{
					WFConnect(WF_DEFAULT);
				}
			while (WFStatus != CONNECTED);
			tcp_socket_handle();//to reset tcp socket
		}
		if(off_flag==1)
		{
			off_flag=0;
			opt_trig=0;
			if(profile.AppEnable)
			{publish_handle();}//to publish any data present before going to sleep
			sprintf(input,"\nLast Wifi Status : %d\n\n",WFStatus);
			UARTWrite(1,input);
			if(profile.OptLevel==LVL_WIFI)
			{
				UARTWrite(1,"Turning Wifi OFF.. \r\n");
				WFHibernate();
			}
			else if(profile.OptLevel==LVL_MICROCONTROLLER)
			{
				UARTWrite(1,"Turning Wifi OFF and Putting Flyport to SLEEP.. \r\n");
				WFSleep();
			}
		}
		
		// Check RTCC alarm flag 
		//Added alarmflag_opt in rttc.c file and clock.h
		if(alarmflag_opt == 1)
		{
			opt_trig++;
			alarmflag_opt = 0;
			vTaskDelay(1);
			//UARTWrite(1, "OPT Rtcc ALARM!!!\r\n\n\n");
			if(WFStatus==TURNED_OFF)
			{
				if(profile.OnType==TIME)
				{
					if(opt_trig>=profile.OffTime)
					{
						on_flag=1;
					}			
				}
			}
			else
			{
				if(opt_trig>=profile.OnTime)
				{
					off_flag=1;
				}
			}
		}
	}
}
Пример #4
0
void FlyportTask()
{	
	vTaskDelay(100);
	UARTWrite(1,"LHINGS on GROVE NEST example!\r\n");

	// Action & Status vars.
	char mEventMsg[] = "PIR_Picus: Someone is moving here!";
	BOOL LedStatus = FALSE;
	int mCont = 0;
	
	// GROVE board
	void *board = new(GroveNest);

	// GROVE devices	
	// Digital Input/outputs
	void *button = new(Dig_io, IN);			// Button/PIR sensor
	attachToBoard(board, button, DIG1);
	void *led = new(Dig_io, OUT);			// Led
	attachToBoard(board, led, DIG2);
	
	// Connection to Network
	#if defined (FLYPORT)
	WFConnect(WF_DEFAULT);
	while (WFStatus != CONNECTED);
	#endif
	#if defined (FLYPORTETH)
	while(!MACLinked);
	#endif
	UARTWrite(1,"Flyport connected!\r\n");
	vTaskDelay(200);
	
	//Turn on/off onboard leds
    IOPut(D4Out, on);
    IOPut(D5Out, off);
	
	// ** INITIALIZE LHINGS **
	// Init. Lhings engine
	if(!LhingsBegin(LHINGS_DEVNAME, LHINGS_DEVUUID, LHINGS_USERNAME, LHINGS_APIKEY))
		UARTWrite(1,"ERROR: Lhings access vars. out of range\r\n");
		
	// Initialize Led status
	set(led, OFF);
	LedStatus = FALSE;
	
	// Set ** LHINGS STATUS vars. **
	// Set the Value of the Status vars. defined above in Lhings_StatusList[]
	LhingsStatusWrite("Led status", "off");
	
	
	while(1)
	{
		// ** Lhings LOOP ** 
		LhingsLoop();
		
		// Check pressure of button / motion detected by PIR sensor 
		if((get(button) != 0) && (mCont==0))
		{
			// Event detected: Publish it in Lhings with a Payload message
			LhingsEventWrite_withPayload("motion", mEventMsg, strlen(mEventMsg), EVT_PAYLOAD);				
			UARTWrite(1, "DIG1 motion detected!\r\n");
			vTaskDelay(20);
			
			// Initialize detection delay counter for PIR sensor
			mCont = 0x0025;
			
			if(LedStatus){
				set(led, OFF);
				LedStatus = FALSE;
				// Set ** LHINGS STATUS vars. **
				// Set the Value of the Status vars. defined above in Lhings_StatusList[]
				LhingsStatusWrite("Led status", "off");
			}
			else{
				set(led, ON);
				LedStatus = TRUE;
				// Set ** LHINGS STATUS vars. **
				// Set the Value of the Status vars. defined above in Lhings_StatusList[]
				LhingsStatusWrite("Led status", "on");
			}
		}
		
		// Process PIR sensor delay
		if(mCont != 0){
			vTaskDelay(5);
			mCont--;
		}
		
		// Check ** LHINGS ACTION ** reception of "switch" action
		if(LhingsActionAvailable("switch")){
			UARTWrite(1,"Action received: switch\r\n");
			
			if(LedStatus){
				set(led, OFF);
				LedStatus = FALSE;
				// Set ** LHINGS STATUS vars. **
				// Set the Value of the Status vars. defined above in Lhings_StatusList[]
				LhingsStatusWrite("Led status", "off");
			}
			else{
				set(led, ON);
				LedStatus = TRUE;
				// Set ** LHINGS STATUS vars. **
				// Set the Value of the Status vars. defined above in Lhings_StatusList[]
				LhingsStatusWrite("Led status", "on");
			}
		}
	}
}