// Initializes the device and connects to the network using Activation By Personalization. // Returns true on successful connection. bool Sodaq_RN2483::initABP(Stream& stream, const uint8_t devAddr[4], const uint8_t appSKey[16], const uint8_t nwkSKey[16]) { debugPrintLn("[initABP]"); init(stream); return resetDevice() && setMacParam(STR_DEV_ADDR, devAddr, 4) && setMacParam(STR_APP_SESSION_KEY, appSKey, 16) && setMacParam(STR_NETWORK_SESSION_KEY, nwkSKey, 16) && //setMacParam(STR_ADR, BOOL_TO_ONOFF(adr)) && joinNetwork(STR_ABP); }
// Initializes the device and connects to the network using Over-The-Air Activation. // Returns true on successful connection. bool Sodaq_RN2483::initOTA(Stream& stream, const uint8_t devEUI[8], const uint8_t appEUI[8], const uint8_t appKey[16]) { debugPrintLn("[initOTA]"); init(stream); return resetDevice() && setMacParam(STR_DEV_EUI, devEUI, 8) && setMacParam(STR_APP_EUI, appEUI, 8) && setMacParam(STR_APP_KEY, appKey, 16) && // setMacParam(STR_ADR, BOOL_TO_ONOFF(adr)) && joinNetwork(STR_OTAA); }
void LoRa::init(LORA_MODE desiredMode){ config->build(desiredMode); resetConfig(); setPublicNetwork(); setFrequencySubBand(); setNetworkName(); setNetworkPassphrase(); setSpreadingFactor(); setAckRetries(); setTxPower(); saveConfig(); if(config->isActiv()){ joinNetwork(); } }
// Initializes the device and connects to the network using Over-The-Air Activation. // Uses HWEUI // Returns true on successful connection. bool Sodaq_RN2483::initOTA(SerialType& stream, const uint8_t appEUI[8], const uint8_t appKey[16], bool adr) { uint8_t devEUI[8]; debugPrintLn("[initOTA]: using hweui"); // assign Serial port init(stream); if (resetDevice()) { getHWEUI(devEUI, 8); // returns ASCII HWEUI from RN module return resetDevice() && setMacParam(STR_DEV_EUI, devEUI, 8) && setMacParam(STR_APP_EUI, appEUI, 8) && setMacParam(STR_APP_KEY, appKey, 16) && setMacParam(STR_ADR, BOOL_TO_ONOFF(adr)) && joinNetwork(STR_OTAA); } return 0; // reset command failed }
bool AFramework::MTempMaster::run(){ AString currentCmd; AString str; AString sensAdd; uint8 temp = 0; if(!m_flag){ return false; } if(joinNetwork()){ /* joinNetwork da direttamente l'output */ if(!loadAll()){ msg("Errore\nCaricamento", 0); while(1); } //cerco per due volte i sensori vicini readTemp(str); for(uint8 i = 0; i < _MTEMP_ROOM_VEC_SIZE; i++){ str.clear(); str = m_rooms[i].sensorAddress(); sensAdd = "Ricerco\nSensore "; sensAdd += m_rooms[i].sensorAddress(); msg(sensAdd); temp = 0; temp = readTemp(str); m_rooms[i].setTemperature(temp); if(temp != 0){ sensAdd.clear(); sensAdd += "Sensore "; sensAdd += m_rooms[i].sensorAddress(); sensAdd += "\nTrovato"; msg(sensAdd); }else{ sensAdd.clear(); sensAdd += "Sensore "; sensAdd += m_rooms[i].sensorAddress(); sensAdd += "\nNon trovato"; msg(sensAdd); } } msg("In ascolto...", 0); m_wifi->prepareForReceive(); PortA.write(bit7, Hi); System::delay(1000); PortA.write(bit7, Lo); ATime time = System::aliveTime(); time.addMinutes(1); while(1){ if(m_wifi->waitForData(currentCmd, 0)){ PortA.write(bit7, Hi); commandExec(currentCmd); PortA.write(bit7, Lo); currentCmd.clear(); }else{ if(System::aliveTime() <= time){ programsManager(false); }else{ programsManager(true); time.addMinutes(1); } } } }else{ /* joinNetwork da direttamente l'output */ while(1); } }
/* This will process library data. It will return true, if nothing was processing -> the data are for the sketch, otherwise, it returns false, so the data are processed here * and nothing should be processed by the sketch. */ boolean RemoteHomeWifi::processCommonData() { if (stringComplete) { if (inputString.startsWith(" ")) { //wifi config createTableWithForm(WIFI_CONFIG, WIFI_CONFIG_ACTION); char* netName = getNetworkName(); createTextBoxTableRow(CAPTION_WIFI_SSID, ACTION_S, netName, MAXSIZE_32); free(netName); createTextBoxTableRow(CAPTION_WIFI_PWD, ACTION_P, "", MAXSIZE_64); createTextBoxTableRow(CAPTION_WIFI_IP, ACTION_I, "", MAXSIZE_15); createSubmitButton(); endTableWithForm(); } else if (inputString.startsWith("ca")) { //device config createTableWithForm(DEVICE_CONFIG, DEVICE_CONFIG_ACTION); char* ip = readIpAddrFromEEPROM(EEPROM_POSITION_SERVER_IP); createTextBoxTableRow(CAPTION_SERVER_IP, ACTION_S, ip, MAXSIZE_15); free(ip); createTextBoxTableRow(CAPTION_SERVER_PORT, ACTION_P, readIntFromEEPROM(EEPROM_POSITION_SERVER_PORT), MAXSIZE_5); createTextBoxTableRow(CAPTION_PGM_PORT, ACTION_R, readIntFromEEPROM(EEPROM_POSITION_SERVER_PROGPORT), MAXSIZE_5); createTextBoxTableRow(CAPTION_DEVICE_ID, ACTION_D, readByteFromEEPROM(EEPROM_POSITION_NODE_ID), MAXSIZE_4); if (0 != fpAppendConfigTable) (*fpAppendConfigTable)(); createSubmitButton(); endTableWithForm(); } else if (inputString.startsWith("cb")) { //sketch upload pageHeadString = F("<meta http-equiv='refresh' content=\"60;URL='/'\"/>"); outputString = F("<p>Programming, the page is going to reload after 1 min.</p>"); sendPageWithMenuAndHeaderResponse(); delay(30); cleanVariablesAfterProcessing(); if (establishConnectionToServer(true, EEPROM_POSITION_SERVER_IP, EEPROM_POSITION_SERVER_PROGPORT)) { delay(10); _ser.print((byte)1); if (!_ser.find("a")) { setup(); } } } else if (inputString.startsWith("cc")) { //it is join network request cc?s=SSID&p=Password&i=192.168.1.30 HTTP/1.1 skipInputToChar('='); String ssid = inputString.substring(0,inputString.indexOf('&')); skipInputToChar('='); String password = inputString.substring(0,inputString.indexOf('&')); skipInputToChar('='); String ip = inputString.substring(0,inputString.indexOf(' ')); pageHeadString = F("<meta http-equiv='refresh' content=\"25;URL='"); if (ip.length() != 0) { pageHeadString += F("http://"); pageHeadString += ip; pageHeadString += F("/"); } pageHeadString += F("cd'\"/>"); outputString = F("<p>Connecting, please wait, the result is going to be displayed within 25 seconds...</p>"); sendPageWithMenuAndHeaderResponse(); if (!joinNetwork(ssid, password, ip)) { becomeAdHocNetwork(); listenOnPort(); connectedToWifi = false; } cleanVariablesAfterProcessing(); } else if (inputString.startsWith("cd")) { if (waitToConnectToNetwork(1)) { outputString = F("<p>Connected:<b>"); outputString += getIPAddress(); outputString += F("</b><BR>Please reserve the IP in your router.</p>"); sendPageWithMenuAndHeaderResponse(); delay(1000); setSingleJoinNetwork(); outputString = ""; } else { outputString = F("<p>Not connected, please try again.</p>"); } } else if (inputString.startsWith("ce")) { //it is configure device: ce?s=192.168.1.2&p=8080&r=8081&d=1&e=0 HTTP/1.1 saveIpAddrToEEPROM(EEPROM_POSITION_SERVER_IP); saveIntToEEPROM(EEPROM_POSITION_SERVER_PORT); saveIntToEEPROM(EEPROM_POSITION_SERVER_PROGPORT); saveByteToEEPROM(EEPROM_POSITION_NODE_ID); nodeId = EEPROM.read(EEPROM_POSITION_NODE_ID); if (0 != fpSaveConfigValues) (*fpSaveConfigValues)(); outputString = F("<p>Configured.</p>"); } else { return true; } if (outputString.length()!=0) { sendPageWithMenuAndHeaderResponse(); } cleanVariablesAfterProcessing(); return false; } return true; }
void RF24Mesh::updateNetworkTopology(void) { if (!rTable.amImaster() && (isState(INIT) || isState(NJOINED))) { setState(NJOINED); joinNetwork(); setState(SENDJOIN); IF_SERIAL_DEBUG(printf_P(PSTR("%lu: Join network called last_join_time: %lu \n\r"),rTable.getMillis(),last_join_time)); } else if (!rTable.amImaster() && (isState(JOINED))) { if (last_join_time == 0 || (millis() - last_join_time) > JOIN_DURATION) //bir dakika { setState(NJOINED); joinNetwork(); setState(SENDJOIN); IF_SERIAL_DEBUG(printf_P(PSTR("%lu: Join network called last_join_time: %lu \n\r"),rTable.getMillis(),last_join_time)); } } else if (isState(NEW_JOINED)) { setState(JOINED); last_join_time = millis(); send_UpdateWeight(); } else if (isState(SENDJOIN)) { if (millis() - state_time >= JOIN_WAIT_WELCOME*2) { sendAckToWelcome(); //TODO sanki buna gerek yok zaten ici bos if(rTable.amIJoinedNetwork()) { setState(JOINED); last_join_time = millis(); IF_SERIAL_DEBUG(printf_P(PSTR("%lu: I have joined the network: %lu \n\r"),rTable.getMillis(),last_join_time)); } else { setState(NJOINED); IF_SERIAL_DEBUG(printf_P(PSTR("%lu: I could ****NOT*** joined the network: %lu \n\r"),rTable.getMillis(),last_join_time)); } } } /* else if(isState(JOINRECEIVED)) { if(rTable.isPathShortened()) { rTable.connectShortened(); send_JoinMessage(); setState(SENDJOIN); } else { sendWelcomeToJoin(); } } */ }
/** * @brief Attempts to connect to the network using Over The Air Activation. * @return Returns true if able to join network. */ bool RN2483::joinOTAA() { return joinNetwork(STR_OTAA); }
/** * @brief Attempts to connect to the network using Activation By Personalization. * @return Returns true if able to join network. */ bool RN2483::joinABP() { return joinNetwork(STR_ABP); }
void UdpSocket::timerTimeout() { joinNetwork(_ip, _port); timer.start(); }