コード例 #1
0
/****************************************************************************
  Function:
    void SelfTest()

  Description:
    This routine performs a self test of the hardware.

  Precondition:
    None

  Parameters:
    None - None

  Returns:
    None

  Remarks:
    None
  ***************************************************************************/
static void SelfTest(void)
{
    char value = 0;
    char* buf[32];
    Exosite_Init("microchip","dv102412",IF_WIFI, 1);
    // Configure Sensor Serial Port
    UARTConfigure(SENSOR_UART, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(SENSOR_UART, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(SENSOR_UART, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(SENSOR_UART, GetPeripheralClock(), 9600);
    UARTEnable(SENSOR_UART, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));

    // Verify MRF24WB/G0MA MAC Address
    if(AppConfig.MyMACAddr.v[0] == 0x00 && AppConfig.MyMACAddr.v[1] == 0x1E)
    {
        //********************************************************************
        // Prints a label using ESC/P commands to a Brother PT-9800PCN printer
        //********************************************************************
        // Send ESC/P Commands to setup printer
        UARTTxBuffer("\033ia\000\033@\033X\002",9); // ESC i a 0 = Put Printer in ESC/P Mode
                                                    // ESC @ = Reset Printer to Default settings
                                                    // ESC X 2 = Specify Character Size
        // Send the Info to Print for the MAC Address label
        UARTTxBuffer("MRF24WB0MA\r",11);
        sprintf((char *)buf,"MAC: %02X%02X%02X%02X%02X%02X",AppConfig.MyMACAddr.v[0],AppConfig.MyMACAddr.v[1],AppConfig.MyMACAddr.v[2],AppConfig.MyMACAddr.v[3],AppConfig.MyMACAddr.v[4], AppConfig.MyMACAddr.v[5]);
        UARTTxBuffer((char *)buf, strlen((const char *)buf));

        // Print the label
        UARTTxBuffer("\f",1);
        
        // Toggle LED's
        while(1)
        {
            LED0_IO = value;
            LED1_IO = value >> 1;
            LED2_IO = value >> 2;

            DelayMs(400);

            if(value == 8)
                value = 0;
            else
                value++;

        }
    }
コード例 #2
0
ファイル: main.c プロジェクト: anderiv/stellaris_atdt_cloud
/*==============================================================================
* main
*
* This is our entry point and main application function.
*=============================================================================*/
int
main(void)
{
  unsigned char pingNum = 0;
  char pingNumStr[5];
  char messageStr[30];
  char valueStr[10];


  //Initialize cloud-communication cependent peripherals & turns on interrupts
  Exosite_Init();

  WriteUILine("Exosite GPRS Demo", LCD_TITLE_LINE);
#ifdef PART_LM3S6965
  WriteUILine("UART0,115200,8,N,1", LCD_UART_LINE);
#endif
#ifdef PART_LM3S1968
  WriteUILine("UART2,115200,8,N,1", LCD_UART_LINE);
#endif
#ifdef PART_RDK_IDM_L35
  WriteUILine("UART2,115200,8,N,1", LCD_UART_LINE);
#endif
  //Start cloud communications
  Exosite_Start();

  // Loop forever in our main app
  while(1)
  {
    WriteUILine("Pre POST", LCD_DEBUG_LINE);
    WriteUILine(LCD_BLANK_LINE, LCD_STATUS_LINE);
    exstrcpy(messageStr, "ping=");
    exitoa(pingNum, pingNumStr);
    exstrcat(messageStr,pingNumStr);
    if (AT_REPLY_OK == Exosite_Write(messageStr)) {
      exstrcat(messageStr," -> POST value");
      WriteUILine(messageStr, LCD_DEBUG_LINE);
    }
    else
    {
      WriteUILine("POST Error", LCD_DEBUG_LINE);
    }

    Delay(2);

    WriteUILine("Pre GET", LCD_DEBUG_LINE);
    WriteUILine(LCD_BLANK_LINE, LCD_STATUS_LINE);
    if (AT_REPLY_OK == Exosite_Read("interval", valueStr)) {
      exstrcpy(messageStr, "interval is: ");
      exstrcat(messageStr,valueStr);
      WriteUILine(messageStr, LCD_DEBUG_LINE);
    }
    else
    {
      WriteUILine("GET Error", LCD_DEBUG_LINE);
    }

#ifdef PUBLICTEMP
    //
    // get public temperature
    //
    Delay(2);

    WriteUILine("Pre GET Temp", LCD_DEBUG_LINE);
    WriteUILine(LCD_BLANK_LINE, LCD_STATUS_LINE);
    if (AT_REPLY_OK == Exosite_Read("pubtemp", valueStr)) {
      exstrcpy(messageStr, "Outside Temp is: ");
    exstrcat(messageStr,valueStr);
    exstrcat(messageStr," F");
    WriteUILine(messageStr, LCD_DEBUG_LINE);
    WriteUILine(messageStr, LCD_DATA_LINE);
    }
    else
    {
      WriteUILine("GET Error", LCD_DEBUG_LINE);
      WriteUILine("Outside Temp Not Available", LCD_DATA_LINE);
    }
#endif

    Delay(LOOPDELAY);

    if (100 == pingNum++)
      pingNum = 0;
  }
}
コード例 #3
0
//*****************************************************************************
//
//!  main
//!
//!  \param  None
//!
//!  \return none
//!
//!  \brief   The main loop is executed here
//
//*****************************************************************************
void main(void)
{
  unsigned char loopCount = 0;
  int loop_time = 2000;

  ulCC3000Connected = 0;
  SendmDNSAdvertisment = 0;

  // Initialize hardware and interfaces
  board_init();
  initUart();
  sendString("System init : \r\n");

  // Must initialize one time for MAC address prepare..
  if (!Exosite_Init("exosite", "cc3000wifismartconfig", IF_WIFI, 0))
  {
    show_status();
    while(1);
  }

  // Main Loop
  while (1)
  {
    // Perform Smart Config if button pressed in current run or if flag set in FRAM
    // from previous MSP430 Run.
    if(runSmartConfig == 1 || *ptrFtcAtStartup == SMART_CONFIG_SET)
    {
      // Clear flag
      ClearFTCflag();
      unsetCC3000MachineState(CC3000_ASSOC);

      // Start the Smart Config Process
      StartSmartConfig();
      runSmartConfig = 0;
    }

    WDTCTL = WDTPW + WDTHOLD;
    // If connectivity is good, run the primary functionality
    if(checkWiFiConnected())
    {
      char * pbuf = exo_buffer;

      //unsolicicted_events_timer_disable();

      if (0 == cloud_status)
      { //check to see if we have a valid connection
        loop_time = 2000;

        loopCount = 1;

        while (loopCount++ <= (WRITE_INTERVAL+1))
        {
//          WDTCTL = WDT_ARST_1000;
          if (Exosite_Read("led7_ctrl", pbuf, EXO_BUFFER_SIZE))
          {
        	// Read success
        	turnLedOn(CC3000_CLIENT_CONNECTED_IND);

            if (!strncmp(pbuf, "0", 1))
              turnLedOff(LED7);
            else if (!strncmp(pbuf, "1", 1))
              turnLedOn(LED7);
          }
          else
          {
        	if (EXO_STATUS_NOAUTH == Exosite_StatusCode())
        	{
        		turnLedOff(CC3000_CLIENT_CONNECTED_IND);
        		// Activate device again
        		cloud_status = Exosite_Activate();
        	}
          }

          hci_unsolicited_event_handler();
          unsolicicted_events_timer_init();
          //sendString("== Exosite Read==\r\n");
          WDTCTL = WDTPW + WDTHOLD;
          busyWait(loop_time);        //delay before looping again
        }

        unsolicicted_events_timer_init();
    	if (EXO_STATUS_NOAUTH != Exosite_StatusCode())
    	{
          unsigned char sensorCount = 0;
          int value;
          char strRead[6]; //largest value of an int in ascii is 5 + null terminate
          WDTCTL = WDT_ARST_1000;
          for (sensorCount = 0; sensorCount < SENSOR_END; sensorCount++)
          {
            value = getSensorResult(sensorCount);                                       //get the sensor reading
            itoa(value, strRead, 10);                           //convert to a string
            unsolicicted_events_timer_init();
            //for each reading / data source (alias), we need to build the string "alias=value" (must be URL encoded)
            //this is all just an iteration of, for example, Exosite_Write("mydata=hello_world",18);
            memcpy(pbuf,&sensorNames[sensorCount][0],strlen(&sensorNames[sensorCount][0]));  //copy alias name into buffer
            pbuf += strlen(&sensorNames[sensorCount][0]);
            *pbuf++ = 0x3d;                                             //put an '=' into buffer
            memcpy(pbuf,strRead, strlen(strRead));                      //copy value into buffer
            pbuf += strlen(strRead);
            *pbuf++ = 0x26;                                             //put an '&' into buffer, the '&' ties successive alias=val pairs together
          }
          pbuf--;                                                                       //back out the last '&'
          WDTCTL = WDT_ARST_1000;
          Exosite_Write(exo_buffer,(pbuf - exo_buffer - 1));    //write all sensor values to the cloud

          if (EXO_STATUS_OK == Exosite_StatusCode())
          { // Write success
    	    turnLedOn(CC3000_CLIENT_CONNECTED_IND);
          }
    	}
      } else {
          //we don't have a good connection yet - we keep retrying to authenticate
    	  WDTCTL = WDTPW + WDTHOLD;
          //sendString("== Exosite Activate==\r\n");
          cloud_status = Exosite_Activate();
          if (0 != cloud_status) loop_time = 30000; //delay 30 seconds before retrying...
      }

        unsolicicted_events_timer_init();
      }
      WDTCTL = WDTPW + WDTHOLD;
      // TODO - make this a sleep instead of busy wait
      busyWait(loop_time);        //delay before looping again
    }
}
コード例 #4
0
// ************************************************************
// Main application entry point.
// ************************************************************
int main(void)
{
    static DWORD t = 0;	
    static DWORD dwLastIP = 0;
#if defined (EZ_CONFIG_STORE)
    static DWORD ButtonPushStart = 0;
#endif
    UINT8         channelList[] = MY_DEFAULT_CHANNEL_LIST_PRESCAN;  // WF_PRESCAN
    tWFScanResult bssDesc;
#if 0	
    INT8 TxPower;   // Needed to change MRF24WG transmit power. 
#endif

    // Initialize application specific hardware
    InitializeBoard();

    // Initialize TCP/IP stack timer
    TickInit();                        //  Timer 3 interrupt for refreshing motor status inside here
    demo_TickInit();

    #if defined(STACK_USE_MPFS2)
    // Initialize the MPFS File System
	// Generate a WifiGDemoMPFSImg.c file using the MPFS utility (refer to Convert WebPages to MPFS.bat)
	// that gets compiled into source code and programmed into the flash of the uP.
    MPFSInit();
    #endif
	
    // Initialize Stack and application related NV variables into AppConfig.
    InitAppConfig();

    // Initialize core stack layers (MAC, ARP, TCP, UDP) and
    // application modules (HTTP, SNMP, etc.)
    StackInit();

    Exosite_Init("microchip","dv102412",IF_WIFI, 0);

#if 0	
    // Below is used to change MRF24WG transmit power. 
    // This has been verified to be functional (Jan 2013) 
    if (AppConfig.networkType == WF_SOFT_AP)
    {
        WF_TxPowerGetMax(&TxPower);                       
        WF_TxPowerSetMax(TxPower);       
    }
#endif

    // Run Self Test if SW0 pressed on startup
    if(SW0_IO == 1)
        SelfTest();

    #ifdef STACK_USE_TELNET_SERVER
        // Initialize Telnet and
        // Put Remote client in Remote Character Echo Mode
        TelnetInit();
        putc(0xff, stdout);     // IAC = Interpret as Command
        putc(0xfe, stdout);     // Type of Operation = DONT
        putc(0x22, stdout);     // Option = linemode
        putc(0xff, stdout);     // IAC = Interpret as Command
        putc(0xfb, stdout);     // Type of Operation = DO
        putc(0x01, stdout);     // Option = echo
    #endif


    #if defined ( EZ_CONFIG_SCAN )
    // Initialize WiFi Scan State Machine NV variables
    WFInitScan();
    #endif
	
    // WF_PRESCAN: Pre-scan before starting up as SoftAP mode  
    WF_CASetScanType(MY_DEFAULT_SCAN_TYPE);
    WF_CASetChannelList(channelList, sizeof(channelList));
		
    if (WFStartScan() == WF_SUCCESS) {
       SCAN_SET_DISPLAY(SCANCXT.scanState);
       SCANCXT.displayIdx = 0;
    }
	
    // Needed to trigger g_scan_done		
    WFRetrieveScanResult(0, &bssDesc);		
  	
    #if defined(STACK_USE_ZEROCONF_LINK_LOCAL)
    // Initialize Zeroconf Link-Local state-machine, regardless of network type.
    ZeroconfLLInitialize();
    #endif
	
    #if defined(STACK_USE_ZEROCONF_MDNS_SD)
    // Initialize DNS Host-Name from TCPIPConfig.h, regardless of network type.
    mDNSInitialize(MY_DEFAULT_HOST_NAME);
    mDNSServiceRegister(
            // (const char *) AppConfig.NetBIOSName,        // base name of the service. Ensure uniformity with CheckHibernate().
            (const char *) "DemoWebServer",          // base name of the service. Ensure uniformity with CheckHibernate().
            "_http._tcp.local",                      // type of the service
            80,	                                     // TCP or UDP port, at which this service is available
            ((const BYTE *)"path=/index.htm"),       // TXT info
            1,                                       // auto rename the service when if needed
            NULL,                                    // no callback function
            NULL                                     // no application context
            );
    mDNSMulticastFilterRegister();
    #endif
	
    #if defined(WF_CONSOLE)
    // Initialize the WiFi Console App
    WFConsoleInit();
    #endif

    // Now that all items are initialized, begin the co-operative
    // multitasking loop.  This infinite loop will continuously
    // execute all stack-related tasks, as well as your own
    // application's functions.  Custom functions should be added
    // at the end of this loop.
    // Note that this is a "co-operative mult-tasking" mechanism
    // where every task performs its tasks (whether all in one shot
    // or part of it) and returns so that other tasks can do their
    // job.
    // If a task needs very long time to do its job, it must be broken
    // down into smaller pieces so that other tasks can have CPU time.
   #ifndef PERIOD
#define PERIOD  3120        //  set 3120 for get to timer interrupt every 20ms, 40MHz PBUS, div by 256
#endif
    OpenTimer3(T3_ON | T3_SOURCE_INT | T3_PS_1_256, PERIOD);
    while(1)
    {
         if (AppConfig.networkType == WF_SOFT_AP) {
            if (g_scan_done) {
                if (g_prescan_waiting) {
                     SCANCXT.displayIdx = 0;
                     while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) {
                         WFDisplayScanMgr();
                     }
				
                     #if defined(WF_CS_TRIS)
                     WF_Connect();
                     #endif
                     g_scan_done = 0;
                     g_prescan_waiting = 0;
                }
            }
         }

        #if defined (EZ_CONFIG_STORE)
        // Hold SW0 for 4 seconds to reset to defaults.
        if (SW0_IO == 1u) {  // Button is pressed
            button_state = 1;
            if (ButtonPushStart == 0)  //Just pressed
                ButtonPushStart = TickGet();
            else
                if(TickGet() - ButtonPushStart > 4*TICK_SECOND)
                    RestoreWifiConfig();
        } 
        else 
        {
            ButtonPushStart = 0; //Button release reset the clock
        }
		
        if (AppConfig.saveSecurityInfo)
        {
            // set true by WF_ProcessEvent after connecting to a new network
            // get the security info, and if required, push the PSK to EEPROM
            if ((AppConfig.SecurityMode == WF_SECURITY_WPA_WITH_PASS_PHRASE) ||
                (AppConfig.SecurityMode == WF_SECURITY_WPA2_WITH_PASS_PHRASE) ||
                (AppConfig.SecurityMode == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE))
            {
                // only need to save when doing passphrase
                tWFCPElements profile;
                UINT8 connState;
                UINT8 connID;
                WF_CMGetConnectionState(&connState, &connID);
                WF_CPGetElements(connID, &profile);
                
                memcpy((char*)AppConfig.SecurityKey, (char*)profile.securityKey, 32);
                AppConfig.SecurityMode--; // the calc psk is exactly one below for each passphrase option
                AppConfig.SecurityKeyLength = 32;                

                SaveAppConfig(&AppConfig);
            }
            
            AppConfig.saveSecurityInfo = FALSE;
        }
        #endif // EZ_CONFIG_STORE
		
        // Blink LED0 twice per sec when unconfigured, once per sec after config
        if((TickGet() - t >= TICK_SECOND/(4ul - (CFGCXT.isWifiDoneConfigure*3ul))))
        {
            t = TickGet();
            LED0_INV();
        }

        // This task performs normal stack task including checking
        // for incoming packet, type of packet and calling
        // appropriate stack entity to process it.
        StackTask();

        // This task invokes each of the core stack application tasks
        if (cloud_mode == 0)
          StackApplications();

        // Enable WF_USE_POWER_SAVE_FUNCTIONS 
        WiFiTask();

        #if defined(STACK_USE_ZEROCONF_LINK_LOCAL)
        ZeroconfLLProcess();
        #endif

        #if defined(STACK_USE_ZEROCONF_MDNS_SD)
        mDNSProcess();
        #endif

        Exosite_Demo();
        // Process application specific tasks here.
        // Any custom modules or processing you need to do should
        // go here.
        #if defined(WF_CONSOLE)
		WFConsoleProcess();
		WFConsoleProcessEpilogue();
		#endif

		// If the local IP address has changed (ex: due to DHCP lease change)
		// write the new IP address to the LCD display, UART, and Announce 
		// service
		if(dwLastIP != AppConfig.MyIPAddr.Val) 
		{
			dwLastIP = AppConfig.MyIPAddr.Val;	
			DisplayIPValue(AppConfig.MyIPAddr);			
		
			#if defined(STACK_USE_ANNOUNCE)
			AnnounceIP();
	 		#endif
		
			#if defined(STACK_USE_ZEROCONF_MDNS_SD)
			mDNSFillHostRecord();
	 		#endif
		}

    }
}
コード例 #5
0
int  main(void)
{
    AppMode_T AppMode; APP_STATE_E state=UPDATE_TEMPERATURE; 
    char LCDString[30], temp_char[2]; uint16_t temp; float ftemp;
  
    HardwareSetup();

    /************************initializa LCD module********************************/
    SPI2_Init();
    InitialiseLCD();
    led_init();
    MSTimerInit();

    /* Default app mode */
    AppMode = GAINSPAN_DEMO;
    
    /* If the CIK is exist, auto into the Exosite mode */
    NVSettingsLoad(&GNV_Setting);
    
    /* Determine if SW1 & SW3 is pressed at power up to enter programming mode */
    if (Switch1IsPressed() && Switch3IsPressed()) {
         AppMode = PROGRAM_MODE;
    }
    else if(Switch3IsPressed() && Switch2IsPressed())
    {
         AppMode = EXOSITE_ERASE;
    }
    else if(Switch1IsPressed())
    {
        AppMode = RUN_EXOSITE;
    }
    else if(Switch2IsPressed())
    {
        AppMode = RUN_PROVISIONING;
    }
    else if(Switch3IsPressed())
    {
        AppMode = RUN_OVER_AIR_DOWNLOAD;
    }
    
    if(AppMode == GAINSPAN_DEMO) {
        LCDDisplayLogo();
        LCDSelectFont(FONT_SMALL);
        DisplayLCD(LCD_LINE3, "RL78G14 RDK    V2.0");
        DisplayLCD(LCD_LINE4, "   Wi-Fi & Cloud   ");
        DisplayLCD(LCD_LINE5, "     demos by:     ");
        DisplayLCD(LCD_LINE6, "Gainspan           ");
        DisplayLCD(LCD_LINE7, "Exosite            ");
        DisplayLCD(LCD_LINE8, "Future Designs, Inc");
        MSTimerDelay(3500);
        ClearLCD();
        DisplayLCD(LCD_LINE1, "Demo Modes:        ");
        DisplayLCD(LCD_LINE2, "-RST no key:       ");
        DisplayLCD(LCD_LINE3, "   GS Web Server   ");
        DisplayLCD(LCD_LINE4, "-RST + SW1:        ");
        DisplayLCD(LCD_LINE5, "   Exosite Cloud   ");
        DisplayLCD(LCD_LINE6, "-RST + SW2:        ");
        DisplayLCD(LCD_LINE7, "   AP Provisioning ");
        DisplayLCD(LCD_LINE8, "-RST + SW3: OTA    ");
        MSTimerDelay(3000);
        ClearLCD();
        
        LCDSelectFont(FONT_LARGE);
        if(Exosite_GetCIK(NULL))
        {
          AppMode = RUN_EXOSITE;
        }
    }
    
    DisplayLCD(LCD_LINE1, "Starting..."); 
    /*****************************************************************************/  
    SPI_Init(GAINSPAN_SPI_RATE);  
   /* Setup LCD SPI channel for Chip Select P10, active low, active per byte  */
    SPI_ChannelSetup(GAINSPAN_SPI_CHANNEL, false, true);
    GainSpan_SPI_Start();

    PM15 &= ~(1 << 2);
    P15 &= ~(1 << 2);
    
    if(AppMode == PROGRAM_MODE) {
        App_ProgramMode();
    }
    else if (AppMode == RUN_EXOSITE)
    {          
        DisplayLCD(LCD_LINE1, " CLOUD DEMO ");
        Temperature_Init();
        Potentiometer_Init();  
        App_Exosite();
    }
    else if(AppMode == RUN_PROVISIONING)
    {
      App_WebProvisioning();
    }
     else if(AppMode == RUN_OVER_AIR_DOWNLOAD)
    {
       App_OverTheAirProgrammingPushMetheod();
    }
    else if (AppMode == EXOSITE_ERASE)
    {
       ClearLCD();
       LCDSelectFont(FONT_SMALL);
       DisplayLCD(LCD_LINE3, "EEPROM ERASING ... ");
       MSTimerDelay(2000);
       Exosite_Init("renesas", "rl78g14", IF_WIFI, 1);
       DisplayLCD(LCD_LINE3, "                   ");
       DisplayLCD(LCD_LINE4, "Please reset device");
       while(1);
    }
    else{
        UART0_Start(GAINSPAN_CONSOLE_BAUD);
       // UART2_Start(GAINSPAN_UART_BAUD);
 
        Temperature_Init();
        Potentiometer_Init();
    
       // sprintf(LCDString, "RDK Demo %s", VERSION_TEXT);
       // DisplayLCD(LCD_LINE1, (const uint8_t *)LCDString);
   
        /* Before doing any tests or apps, startup the module */
        /* and nonvolatile stettings */
        App_Startup();
        // Now connect to the system
        //App_Connect(&G_nvsettings.webprov);
     
       //  App_PassThroughSPI();
         
         /******************Start Processing Sensor data******************/
         
         uint32_t start = MSTimerGet();  uint8_t c;
         Accelerometer_Init();
         while(1) 
         { 
          // if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, &c)) 
           if(App_Read(&c, 1, 0)) 
             AtLibGs_ReceiveDataProcess(c);
                   
        /* Timeout? */
           if (MSTimerDelta(start) >= 100)     // every 100 ms, read sensor data
           {  
              led_task();
              switch(state)
              {              
                case UPDATE_TEMPERATURE:         
                // Temperature sensor reading
                  temp = Temperature_Get();
#if 0                 
                   // Get the temperature and show it on the LCD
                  temp_char[0] = (int16_t)temp / 16;
                  temp_char[1] = (int16_t)((temp & 0x000F) * 10) / 16;
#endif 
                  temp_char[1] = (temp & 0xFF00)>>8;
                  temp_char[0] = temp & 0xFF;
                  
                  ftemp = *(uint16_t *)temp_char;
                  
                  gTemp_F = ((ftemp/5)*9)/128 + 22;
              
                  // Display the contents of lcd_buffer onto the debug LCD 
                  //sprintf((char *)LCDString, "TEMP: %d.%d C", temp_char[0], temp_char[1]);
                  sprintf((char *)LCDString, "TEMP: %.1fF", gTemp_F);
                  DisplayLCD(LCD_LINE6, (const uint8_t *)LCDString);  
                  state = UPDATE_LIGHT;
                break;
                
                case UPDATE_LIGHT:
                 // Light sensor reading
                  gAmbientLight = LightSensor_Get();
                    // Display the contents of lcd_buffer onto the debug LCD 
                  sprintf((char *)LCDString, "Light: %d ", gAmbientLight);
                  DisplayLCD(LCD_LINE7, (const uint8_t *)LCDString);
                  state = UPDATE_ACCELEROMETER;
                break;
                
                case UPDATE_ACCELEROMETER: 
                 // 3-axis accelerometer reading
                  Accelerometer_Get();
                  sprintf((char *)LCDString, "x%2d y%2d z%2d", gAccData[0], gAccData[1], gAccData[2]);
                  DisplayLCD(LCD_LINE8, (const uint8_t *)LCDString); 
                  state = UPDATE_TEMPERATURE;
                break;
              }
              start = MSTimerGet();
           }
         }          
    }    
コード例 #6
0
ファイル: main.c プロジェクト: Ascenix/uip_rx62n_cloud
/*----------------------------------------------------------------------------*/ 
int
main(void)
{
  int i;
  // Renesas -- uip_ipaddr_t ipaddr;
  struct timer periodic_timer, arp_timer;
  struct uip_eth_addr my_mac;
  
  uint32_t ch = 0;

  // Renesas ++
  InitialiseLCD();
  DisplayuIPDemo();

  timer_init();
  timer_set(&periodic_timer, CLOCK_SECOND / 2);
  timer_set(&arp_timer, CLOCK_SECOND * 10);

  Exosite_Get_MAC((unsigned char *)&my_mac);
  // Renesas -- network_device_init();
  /* Wait until Ether device initailize succesfully. 
     Make sure Ethernet cable is plugged in. */ 
  while (R_ETHER_ERROR == R_Ether_Open(ch, (uint8_t*)&my_mac));

  // Renesas ++ set Ethernet address
  uip_setethaddr(my_mac);
  uip_init();

  // Renesas -- 
  //uip_ipaddr(ipaddr, 192,168,0,2);
  //uip_sethostaddr(ipaddr);
  dhcpc_init(&my_mac, 6);
  if (!Exosite_Init(APP_NAME, APP_VERSION)) DisplayLCD(LCD_LINE8, "==NEED CIK=="); 

  while (1)
  {
    // Renesas -- uip_len = network_device_read();
    uip_len = R_Ether_Read(ch, (void *)uip_buf);
    if (uip_len > 0)
    {
      if (BUF->type == htons(UIP_ETHTYPE_IP))
      {
        uip_arp_ipin();
        uip_input();
        /* If the above function invocation resulted in data that
           should be sent out on the network, the global variable
           uip_len is set to a value > 0. */
        if (uip_len > 0)
        {
          uip_arp_out();
          // Renesas -- network_device_send();
          R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len);
        }
      }
      else if (BUF->type == htons(UIP_ETHTYPE_ARP))
      {
        uip_arp_arpin();
        /* If the above function invocation resulted in data that
           should be sent out on the network, the global variable
           uip_len is set to a value > 0. */
        if (uip_len > 0)
        {
          // Renesas -- network_device_send();
          R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len);
        }
      }

    }
    else if (timer_expired(&periodic_timer))
    {
      timer_reset(&periodic_timer);
      for (i = 0; i < UIP_CONNS; i++)
      {
        uip_periodic(i);
        /* If the above function invocation resulted in data that
           should be sent out on the network, the global variable
           uip_len is set to a value > 0. */
        if (uip_len > 0)
        {
          uip_arp_out();
          // Renesas -- network_device_send();
          R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len);
        }
      }

#if UIP_UDP
      for (i = 0; i < UIP_UDP_CONNS; i++)
      {
        uip_udp_periodic(i);
        /* If the above function invocation resulted in data that
           should be sent out on the network, the global variable
           uip_len is set to a value > 0. */
        if (uip_len > 0)
        {
          uip_arp_out();
          // Renesas -- network_device_send();
          R_Ether_Write(ch, (void *)uip_buf, (uint32_t)uip_len);
        }
      }
#endif /* UIP_UDP */

      /* Call the ARP timer function every 10 seconds. */
      if (timer_expired(&arp_timer))
      {
        timer_reset(&arp_timer);
        uip_arp_timer();
      }
    }

    // Insert user aplications here.
    // Call WEB application that controls LEDs on the target board.
    user_app();
	
  }
  return 0;
}
コード例 #7
0
/*
*********************************************************************************************************
*                                           CloudData_Task()
*
* Description : Sends sensor data to the cloud
*
* Argument(s) : p_arg           Argument passed to 'CloudData_Task()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Caller(s)   : This is a task.
*
* Note(s)     : none.
*********************************************************************************************************
*/
static void CloudData_Task (void *p_arg)
{
    OS_ERR       err;
    CPU_CHAR    *keys[1];
    CPU_CHAR    *values[1];
    CPU_CHAR     strping[4];
    CPU_CHAR     ping = 0;
    CPU_CHAR     ledctrl;
    CPU_CHAR     read_count = 0;
    CPU_BOOLEAN  cloud_available;
    CPU_CHAR     showMAC[18];

    (void)p_arg;

    keys[0] = "ping";
    values[0] = strping;

    // OS Name = "Micrium-Ex1" <- MAX Length = 24
    // OS Ver  = "3.01.2" <- MAX Length = 8
    // Use network interface '1' MAC address
    cloud_available = Exosite_Init("renesas", "Micrium-Ex7", "3.01.2", (NET_IF_NBR)1);
	
	lcd_display(LCD_LINE7, "            ");	
    lcd_display(LCD_LINE8, "            ");	
	if (Exosite_GetMAC(&showMAC[0]) && !DisableCloudStatus)
    {
        lcd_display(LCD_LINE6,(uint8_t *) showMAC);
    }
	
    OSTimeDlyHMSM((CPU_INT16U) 0u,
                  (CPU_INT16U) 0u,
                  (CPU_INT16U) 4u,
                  (CPU_INT32U) 0u,
                  (OS_OPT    ) OS_OPT_TIME_HMSM_NON_STRICT,
                  (OS_ERR   *)&err);

	lcd_display(LCD_LINE6, "            ");				  
	lcd_display(LCD_LINE7, "Cloud Status");

    while (DEF_TRUE)
    {
        if (DEF_TRUE != cloud_available)
        {
            UI_Update(MSG_UNAVAILABLE);

            // Sleep 20 seconds
            OSTimeDlyHMSM((CPU_INT16U)  0u,
                          (CPU_INT16U)  0u,
                          (CPU_INT16U) 20u,
                          (CPU_INT32U)  0u,
                          (OS_OPT    ) OS_OPT_TIME_HMSM_NON_STRICT,
                          (OS_ERR   *)&err);

            // Retry cloud activation until successful
            cloud_available = Exosite_Reinit();
        }
        else
        {
            if (read_count++ > 10) {
                read_count = 0;
                // Create string from ping value
                Str_FmtNbr_Int32U(ping++,
                                  3u,
                                  DEF_NBR_BASE_DEC,
                                  ASCII_CHAR_NULL,
                                  DEF_NO,
                                  DEF_YES,
                                 &strping[0]);

                if (DEF_TRUE != Exosite_Write_Batch(keys, values, 1))
                {
                    UI_Update(MSG_WRITE_ERROR);
                }
                else
                {
                    UI_Update(MSG_CONNECTED);
                }
            }

            if ((CPU_SIZE_T)1 == Exosite_Read("led_ctrl", &ledctrl, 1))
            {
                UI_Update(MSG_CONNECTED);
				ErrorCount = 0;
                
                if ('0' == ledctrl)
                {
                    AppCloudControlLedOn = 0;
                }
                if ('1' == ledctrl)
                {
                    AppCloudControlLedOn = 1;
                }
            } else {
				ErrorCount++;
				if (ErrorCount > 3)
			       UI_Update(MSG_READ_ERROR);
			}

            // Sleep 2 seconds
            OSTimeDlyHMSM((CPU_INT16U) 0u,
                          (CPU_INT16U) 0u,
                          (CPU_INT16U) 2u,
                          (CPU_INT32U) 0u,
                          (OS_OPT    ) OS_OPT_TIME_HMSM_NON_STRICT,
                          (OS_ERR   *)&err);
        }
    }
}
コード例 #8
0
/*****************************************************************************
*
*  App_Exosite
*
*  \param  None
*
*  \return None
*
*  \brief  Takse a reading of temperature and potentiometer and sends to
*          Exosite cloud using a TCP connection
*
*****************************************************************************/
void App_Exosite(void)
{
  int loop_time = 1000;
  unsigned char loopCount = 0;
  int wifi_init = 0;
  int badcik = 1;
  static const uint8_t geoCert[] = { 0x30, 0x82, 0x03, 0x54, 0x30, 0x82, 0x02, 0x3c, 0xa0, 0x03,
                                     0x02, 0x01, 0x02, 0x02, 0x03, 0x02, 0x34, 0x56, 0x30, 0x0d,
                                     0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
                                     0x05, 0x05, 0x00, 0x30, 0x42, 0x31, 0x0b, 0x30, 0x09, 0x06,
                                     0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x16,
                                     0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x47,
                                     0x65, 0x6f, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x49, 0x6e,
                                     0x63, 0x2e, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
                                     0x03, 0x13, 0x12, 0x47, 0x65, 0x6f, 0x54, 0x72, 0x75, 0x73,
                                     0x74, 0x20, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x43,
                                     0x41, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x32, 0x30, 0x35, 0x32,
                                     0x31, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d,
                                     0x32, 0x32, 0x30, 0x35, 0x32, 0x31, 0x30, 0x34, 0x30, 0x30,
                                     0x30, 0x30, 0x5a, 0x30, 0x42, 0x31, 0x0b, 0x30, 0x09, 0x06,
                                     0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x16,
                                     0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0d, 0x47,
                                     0x65, 0x6f, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x49, 0x6e,
                                     0x63, 0x2e, 0x31, 0x1b, 0x30, 0x19, 0x06, 0x03, 0x55, 0x04,
                                     0x03, 0x13, 0x12, 0x47, 0x65, 0x6f, 0x54, 0x72, 0x75, 0x73,
                                     0x74, 0x20, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x20, 0x43,
                                     0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a,
                                     0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00,
                                     0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02,
                                     0x82, 0x01, 0x01, 0x00, 0xda, 0xcc, 0x18, 0x63, 0x30, 0xfd,
                                     0xf4, 0x17, 0x23, 0x1a, 0x56, 0x7e, 0x5b, 0xdf, 0x3c, 0x6c,
                                     0x38, 0xe4, 0x71, 0xb7, 0x78, 0x91, 0xd4, 0xbc, 0xa1, 0xd8,
                                     0x4c, 0xf8, 0xa8, 0x43, 0xb6, 0x03, 0xe9, 0x4d, 0x21, 0x07,
                                     0x08, 0x88, 0xda, 0x58, 0x2f, 0x66, 0x39, 0x29, 0xbd, 0x05,
                                     0x78, 0x8b, 0x9d, 0x38, 0xe8, 0x05, 0xb7, 0x6a, 0x7e, 0x71,
                                     0xa4, 0xe6, 0xc4, 0x60, 0xa6, 0xb0, 0xef, 0x80, 0xe4, 0x89,
                                     0x28, 0x0f, 0x9e, 0x25, 0xd6, 0xed, 0x83, 0xf3, 0xad, 0xa6,
                                     0x91, 0xc7, 0x98, 0xc9, 0x42, 0x18, 0x35, 0x14, 0x9d, 0xad,
                                     0x98, 0x46, 0x92, 0x2e, 0x4f, 0xca, 0xf1, 0x87, 0x43, 0xc1,
                                     0x16, 0x95, 0x57, 0x2d, 0x50, 0xef, 0x89, 0x2d, 0x80, 0x7a,
                                     0x57, 0xad, 0xf2, 0xee, 0x5f, 0x6b, 0xd2, 0x00, 0x8d, 0xb9,
                                     0x14, 0xf8, 0x14, 0x15, 0x35, 0xd9, 0xc0, 0x46, 0xa3, 0x7b,
                                     0x72, 0xc8, 0x91, 0xbf, 0xc9, 0x55, 0x2b, 0xcd, 0xd0, 0x97,
                                     0x3e, 0x9c, 0x26, 0x64, 0xcc, 0xdf, 0xce, 0x83, 0x19, 0x71,
                                     0xca, 0x4e, 0xe6, 0xd4, 0xd5, 0x7b, 0xa9, 0x19, 0xcd, 0x55,
                                     0xde, 0xc8, 0xec, 0xd2, 0x5e, 0x38, 0x53, 0xe5, 0x5c, 0x4f,
                                     0x8c, 0x2d, 0xfe, 0x50, 0x23, 0x36, 0xfc, 0x66, 0xe6, 0xcb,
                                     0x8e, 0xa4, 0x39, 0x19, 0x00, 0xb7, 0x95, 0x02, 0x39, 0x91,
                                     0x0b, 0x0e, 0xfe, 0x38, 0x2e, 0xd1, 0x1d, 0x05, 0x9a, 0xf6,
                                     0x4d, 0x3e, 0x6f, 0x0f, 0x07, 0x1d, 0xaf, 0x2c, 0x1e, 0x8f,
                                     0x60, 0x39, 0xe2, 0xfa, 0x36, 0x53, 0x13, 0x39, 0xd4, 0x5e,
                                     0x26, 0x2b, 0xdb, 0x3d, 0xa8, 0x14, 0xbd, 0x32, 0xeb, 0x18,
                                     0x03, 0x28, 0x52, 0x04, 0x71, 0xe5, 0xab, 0x33, 0x3d, 0xe1,
                                     0x38, 0xbb, 0x07, 0x36, 0x84, 0x62, 0x9c, 0x79, 0xea, 0x16,
                                     0x30, 0xf4, 0x5f, 0xc0, 0x2b, 0xe8, 0x71, 0x6b, 0xe4, 0xf9,
                                     0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x53, 0x30, 0x51, 0x30,
                                     0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04,
                                     0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03,
                                     0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc0, 0x7a, 0x98,
                                     0x68, 0x8d, 0x89, 0xfb, 0xab, 0x05, 0x64, 0x0c, 0x11, 0x7d,
                                     0xaa, 0x7d, 0x65, 0xb8, 0xca, 0xcc, 0x4e, 0x30, 0x1f, 0x06,
                                     0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14,
                                     0xc0, 0x7a, 0x98, 0x68, 0x8d, 0x89, 0xfb, 0xab, 0x05, 0x64,
                                     0x0c, 0x11, 0x7d, 0xaa, 0x7d, 0x65, 0xb8, 0xca, 0xcc, 0x4e,
                                     0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
                                     0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
                                     0x35, 0xe3, 0x29, 0x6a, 0xe5, 0x2f, 0x5d, 0x54, 0x8e, 0x29,
                                     0x50, 0x94, 0x9f, 0x99, 0x1a, 0x14, 0xe4, 0x8f, 0x78, 0x2a,
                                     0x62, 0x94, 0xa2, 0x27, 0x67, 0x9e, 0xd0, 0xcf, 0x1a, 0x5e,
                                     0x47, 0xe9, 0xc1, 0xb2, 0xa4, 0xcf, 0xdd, 0x41, 0x1a, 0x05,
                                     0x4e, 0x9b, 0x4b, 0xee, 0x4a, 0x6f, 0x55, 0x52, 0xb3, 0x24,
                                     0xa1, 0x37, 0x0a, 0xeb, 0x64, 0x76, 0x2a, 0x2e, 0x2c, 0xf3,
                                     0xfd, 0x3b, 0x75, 0x90, 0xbf, 0xfa, 0x71, 0xd8, 0xc7, 0x3d,
                                     0x37, 0xd2, 0xb5, 0x05, 0x95, 0x62, 0xb9, 0xa6, 0xde, 0x89,
                                     0x3d, 0x36, 0x7b, 0x38, 0x77, 0x48, 0x97, 0xac, 0xa6, 0x20,
                                     0x8f, 0x2e, 0xa6, 0xc9, 0x0c, 0xc2, 0xb2, 0x99, 0x45, 0x00,
                                     0xc7, 0xce, 0x11, 0x51, 0x22, 0x22, 0xe0, 0xa5, 0xea, 0xb6,
                                     0x15, 0x48, 0x09, 0x64, 0xea, 0x5e, 0x4f, 0x74, 0xf7, 0x05,
                                     0x3e, 0xc7, 0x8a, 0x52, 0x0c, 0xdb, 0x15, 0xb4, 0xbd, 0x6d,
                                     0x9b, 0xe5, 0xc6, 0xb1, 0x54, 0x68, 0xa9, 0xe3, 0x69, 0x90,
                                     0xb6, 0x9a, 0xa5, 0x0f, 0xb8, 0xb9, 0x3f, 0x20, 0x7d, 0xae,
                                     0x4a, 0xb5, 0xb8, 0x9c, 0xe4, 0x1d, 0xb6, 0xab, 0xe6, 0x94,
                                     0xa5, 0xc1, 0xc7, 0x83, 0xad, 0xdb, 0xf5, 0x27, 0x87, 0x0e,
                                     0x04, 0x6c, 0xd5, 0xff, 0xdd, 0xa0, 0x5d, 0xed, 0x87, 0x52,
                                     0xb7, 0x2b, 0x15, 0x02, 0xae, 0x39, 0xa6, 0x6a, 0x74, 0xe9,
                                     0xda, 0xc4, 0xe7, 0xbc, 0x4d, 0x34, 0x1e, 0xa9, 0x5c, 0x4d,
                                     0x33, 0x5f, 0x92, 0x09, 0x2f, 0x88, 0x66, 0x5d, 0x77, 0x97,
                                     0xc7, 0x1d, 0x76, 0x13, 0xa9, 0xd5, 0xe5, 0xf1, 0x16, 0x09,
                                     0x11, 0x35, 0xd5, 0xac, 0xdb, 0x24, 0x71, 0x70, 0x2c, 0x98,
                                     0x56, 0x0b, 0xd9, 0x17, 0xb4, 0xd1, 0xe3, 0x51, 0x2b, 0x5e,
                                     0x75, 0xe8, 0xd5, 0xd0, 0xdc, 0x4f, 0x34, 0xed, 0xc2, 0x05,
                                     0x66, 0x80, 0xa1, 0xcb, 0xe6, 0x33};

  bool isTimeSync = false;

  // wait 1 sec for LCD messages display
  MSTimerDelay(1000);
  NVSettingsLoad(&GNV_Setting);

#ifdef SHOW_VERSION
  DisplayLCD(LCD_LINE2, (const uint8_t *)ExositeAppVersion);
#endif

  // must initialize one time for mac address prepare..
  WIFI_init(1);
  if (!Exosite_Init("renesas", "rl78g14", IF_WIFI, 0))
  {
    show_status();
    while(1);
  }

  while(AtLibGs_AddCert(  EXOSITE_CA_NAME,
                          true,
                          geoCert,
                          sizeof(geoCert)) != ATLIBGS_MSG_ID_OK)
  {
    DisplayLCD(LCD_LINE4, "Add CA FAILED");
  }

  while (1)
  {
    if (!checkWiFiConnected(wifi_init))
    {
      wifi_init = 0;
    }
    else
    {
      if(!isTimeSync)
      {
        if(Exosite_SyncTime() == 0)
          isTimeSync = true;
      }
      
      UpdateReadings();

      int code = Exosite_StatusCode();
      if (code == EXO_STATUS_OK)
      {
        badcik = 0;
        wifi_init = 1;

        ReadCloudCommands();

        if (loopCount++ >= WRITE_INTERVAL) 
        {
          // POST the Sensor and templature values
          ReportReadings();
          loopCount = 0;
        }
        loop_time = 500; //delay 0.5 seconds before next turn..
      }
      else if (1 == badcik || EXO_STATUS_BAD_CIK == code || EXO_STATUS_NOAUTH == code)
      {
        DisplayLCD(LCD_LINE6, "  Exosite  ");
        DisplayLCD(LCD_LINE7, " Connecting");
        DisplayLCD(LCD_LINE8, "           ");

        if (!Exosite_Activate())
        {
          badcik = 1;
          loop_time = 3000; // delay 3 seconds
        }
        else
        {
          DisplayLCD(LCD_LINE7, " Connected ");
        }
      }
      show_status();
    }

    MSTimerDelay(loop_time);  //delay before looping again
  }
}