// The loop function is called in an endless loop void loop() { // This artificial delay is kept here to avoid endless spinning // of Arduino microcontroller. Modify it as per specfic application needs. delay(2000); // This call displays the amount of free SRAM available on Arduino PrintArduinoMemoryStats(); if (OCProcess() != OC_STACK_OK) { OC_LOG(ERROR, TAG, PCF("OCStack process error")); return; } ChangeTHRepresentation(NULL); }
//The setup function is called once at startup of the sketch void setup() { Serial.begin(115200); // Add your initialization code here OC_LOG_INIT(); OC_LOG(DEBUG, TAG, PCF("OCServer is starting...")); // uint16_t port = OC_WELL_KNOWN_PORT; // Connect to Ethernet or WiFi network if (ConnectToNetwork() != 0) { OC_LOG(ERROR, TAG, "Unable to connect to network"); return; } // Initialize the OC Stack in Server mode if (OCInit(NULL, OC_WELL_KNOWN_PORT, OC_SERVER) != OC_STACK_OK) { OC_LOG(ERROR, TAG, PCF("OCStack init error")); return; } OCStartPresence(60); // Declare and create the example resource createResource(); // This call displays the amount of free SRAM available on Arduino PrintArduinoMemoryStats(); #if (ARDUINO == 0) ble.init( (long)115200, BLE_MASTER, trackeeID); #elif (ARDUINO == 1) ble.init( (long)115200, BLE_SLAVER, slaveList[0]); #elif (ARDUINO == 2) ble.init( (long)115200, BLE_SLAVER, slaveList[1]); #endif // ble.StatusRead(); OC_LOG_V(INFO, TAG, "Program Start-\r\n"); }
// The loop function is called in an endless loop void loop() { // This artificial delay is kept here to avoid endless spinning // of Arduino microcontroller. Modify it as per specific application needs. delay(DELAY_TIME_INPUT_THREAD); checkInputThread(); PrintArduinoMemoryStats(); // This call displays the amount of free SRAM available on Arduino //PrintArduinoMemoryStats(); // Give CPU cycles to OCStack to perform send/recv and other OCStack stuff if (OCProcess() != OC_STACK_OK) { OIC_LOG(ERROR, TAG, ("OCStack process error")); return; } //yield(); }
void ChangePROXIRepresentation (void *param) { (void)param; OCStackResult result = OC_STACK_ERROR; float avg[SLAVER_EA] = {0,}; for (int i = 0; i < SLAVER_EA; i++) { if ( rssicnt[i] > arraysize - 1) { rssicnt[i] = rssicnt[i] % arraysize; } ble.streamDummy(NULL, NULL); /* if( ble.pollingConnect(&slaveList[slaver_num][0]) == false ) { OC_LOG_V("Error : Not Connected.\r\n"); }*/ while (ble.pollingConnect(&slaveList[slaver_num][0]) == false) { ble.streamDummy(NULL, NULL); } if ( ble.IsConnected() == true ) { // print the string when a newline arrives: OC_LOG_V(INFO, TAG, "Connected. (%s)\r\n", slaveList[slaver_num]); // time = millis(); for (int j = 0; j < RSSI_EA; j++) { rssi[i][rssicnt[i]] = ble.pollingGetRSSI(); OC_LOG_V(INFO, TAG, "rssi val : %d \r\n", rssi[i][rssicnt[i]]); rssicnt[i]++; } // oldTime = millis(); // float TpR = (float)(((oldTime-time)/1000.0)/20.0); // OC_LOG_V("time per rssi : %d.%03d\r\n", (int)TpR, (int)(TpR*1000.0 -((int)TpR)*1000.0) ); while ( ble.IsSelfArduino() == false ) ble.pollingDisconnect(); slaver_num++; slaver_num = slaver_num % SLAVER_EA; } avg[i] = CalculateExponentialAverage(RSSI_EA, rssi[i], startindex[i], flag[i]); Serial.println(avg[i]); Serial.print("distance : "); PROXI.m_distance[i] = calculateDistance(avg[i], -58); if (PROXI.m_distance[i] <= 1) { PROXI.m_proximity[i] = 1; } else if (PROXI.m_distance[i] <= 2) { PROXI.m_proximity[i] = 2; } else { PROXI.m_proximity[i] = 3; } Serial.println(PROXI.m_distance[i]); Serial.println(PROXI.m_proximity[i]); //Serial.println(calculateDistance(avg[i], -58)); startindex[i] += RSSI_EA; // This call displays the amount of free SRAM available on Arduino PrintArduinoMemoryStats(); if (startindex[i] >= arraysize) { startindex[i] = 0; } if (flag[i] < (arraysize / RSSI_EA)) { flag[i]++; } } result = OCNotifyAllObservers (m_handle, OC_NA_QOS); if (OC_STACK_NO_OBSERVERS == result) { OC_LOG_V(INFO, TAG, "g_PROXIUnderObservation is 0." ); g_PROXIUnderObservation = 0; } }