bool Ubidots::sendAll(){ bool connected = checkConnection(); char* _packet = (char *) malloc(sizeof(char) * PACKETSIZE); populatePacket(_packet); if (strstr(_packet, "ERROR") != NULL || strlen(_packet) > PACKETSIZE){ free(_packet); return false; // Could not populate the array or max bytes size exceed } while (!connected){ connected = checkConnection(); loraConnect(_band); //Attempts to connect delay(1000); } if (!connected){ free(_packet); return false; // The device is not connected } Serial.print("AT+SEND="); Serial.print(_packet); Serial.print("\r\n"); if(!readGateway(1000)){ free(_packet); return false; } Serial.flush(); free(_packet); delay(100); return true; }
bool Ubidots::loraConnect(uint8_t band) { // Checks if AT commands are available Serial.print("AT\r\n"); if(!readGateway()){ return false; } // Sets the ssid Serial.print("AT+NI=1,"); Serial.print(_ssid); Serial.print("\r\n"); if(!readGateway()){ return false; } // Sets the passphrase to connect Serial.print("AT+NK=1,"); Serial.print(_pass); Serial.print("\r\n"); if(!readGateway()){ return false; } // Sets the band number Serial.print("AT+FSB="); Serial.print(band); Serial.print("\r\n"); if(!readGateway()){ return false; } // Attempts JOIN Serial.print("AT+JOIN\r\n"); delay(5000); if(!readGateway()){ return false; } return true; }
/*--------------------------------------------------------------------------*/ static BOOL Load_primitives_from_gateway_xml_file(char *modulename) { BOOL bOK = FALSE; if (modulename) { struct gateway_struct *currentGateway = NULL; currentGateway = readGateway(modulename); if (currentGateway) { int i = 0; for (i = 0; i < currentGateway->dimLists; i++) { if (currentGateway->primitivesList[i]) { int GATEWAY_ID = currentGateway->gatewayIdList[i]; int PRIMITIVE_ID = currentGateway->primiviteIdList[i]; Add_a_Scilab_primitive_in_hashtable(currentGateway->primitivesList[i], &GATEWAY_ID, &PRIMITIVE_ID); } } /* FREE struct currentGateway */ freeArrayOfString(currentGateway->primitivesList,currentGateway->dimLists); if (currentGateway->primiviteIdList) { FREE(currentGateway->primiviteIdList); currentGateway->primiviteIdList = NULL; } if (currentGateway->gatewayIdList) { FREE(currentGateway->gatewayIdList); currentGateway->gatewayIdList = NULL; } FREE(currentGateway); currentGateway = NULL; bOK = TRUE; } } return bOK; }