Temperature reading demo
Dependencies: DHT libmDot mbed-rtos mbed
Revision 6:0a7760eeaba9, committed 2015-10-21
- Comitter:
- SomeRandomBloke
- Date:
- Wed Oct 21 23:12:33 2015 +0000
- Parent:
- 5:48eb9245a914
- Child:
- 7:2a704d1a30e1
- Commit message:
- Updates to Node address values
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Oct 20 14:48:11 2015 +0000
+++ b/main.cpp Wed Oct 21 23:12:33 2015 +0000
@@ -33,7 +33,9 @@
// Network session key
uint8_t NwkSKey[16]= {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C};
// Dev addr
-uint8_t NodeAddr[4]= {0x23,0x05,0x19,0x67};
+//uint8_t NodeAddr[4]= {0x23,0x05,0x19,0x67};
+// Network Address
+uint8_t NetworkAddr[4]= {0x23,0x05,0x19,0x67};
// Ignoring sub band for EU modules.
//static uint8_t config_frequency_sub_band = 1;
@@ -68,6 +70,7 @@
std::vector<uint8_t> recv_data;
std::vector<uint8_t> nwkSKey;
std::vector<uint8_t> nodeAddr;
+ std::vector<uint8_t> networkAddr;
float temperature = 0.0;
@@ -95,22 +98,26 @@
for (uint8_t i = 0; i<16; i++)
nwkSKey.push_back((uint8_t) *it++);
- it = NodeAddr;
+// it = NodeAddr;
+// for (uint8_t i = 0; i<4; i++)
+// nodeAddr.push_back((uint8_t) *it++);
+
+ it = NetworkAddr;
for (uint8_t i = 0; i<4; i++)
- nodeAddr.push_back((uint8_t) *it++);
+ networkAddr.push_back((uint8_t) *it++);
// Reset config if network name is different or pin is low then reset config.
// if( config_network_name.compare(configNetworkName) != 0 || !configReset ) {
- if( !configReset ) {
+// if( !configReset ) {
// Config Reset link present
logInfo("Resetting Config");
// reset to default config so we know what state we're in
dot->resetConfig();
- }
+// }
// Set byte order - AEP less than 1.0.30
// dot->setJoinByteOrder(mDot::MSB);
- dot->setJoinByteOrder(mDot::LSB);
+// dot->setJoinByteOrder(mDot::LSB);
logInfo("Set Public mode");
if((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) {
@@ -149,7 +156,7 @@
logInfo("Set Ack");
// 1 retries on Ack, 0 to disable
- if((ret = dot->setAck( 1 )) != mDot::MDOT_OK) {
+ if((ret = dot->setAck( 0 )) != mDot::MDOT_OK) {
logError("Failed to set Ack %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
@@ -159,9 +166,9 @@
// logError(dot, "failed to set frequency sub band", ret);
// }
- logInfo("Set Network Key");
- if ((ret = dot->setNetworkKey(nwkSKey)) != mDot::MDOT_OK) {
- logError("Failed to set Network Key %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+ logInfo("Set Network Address");
+ if ((ret = dot->setNetworkAddress(networkAddr)) != mDot::MDOT_OK) {
+ logError("Failed to set Network Address %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
logInfo("Set Network Session Key");
@@ -200,26 +207,19 @@
pc.printf("Data Session Key: ");
pc.printf("%s\r\n", mts::Text::bin2hexString(tmp, " ").c_str());
- logInfo("Joining Network");
-
- while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
- logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
- wait_ms(dot->getNextTxMs() + 1);
- }
-
- logInfo("Joined Network");
-
- pc.printf("Net ID ");
- std::vector<uint8_t> nodeAddress;
- nodeAddress = dot->getNetworkId();
- for (std::vector<uint8_t>::iterator it = nodeAddress.begin() ; it != nodeAddress.end(); ++it)
+ pc.printf("Device ID ");
+ std::vector<uint8_t> deviceId;
+ deviceId = dot->getDeviceId();
+ for (std::vector<uint8_t>::iterator it = deviceId.begin() ; it != deviceId.end(); ++it)
pc.printf("%2.2x",*it );
+ pc.printf("\r\n");
- pc.printf("\r\n");
- pc.printf("Node ID ");
- nodeAddress = dot->getNetworkAddress();
- for (std::vector<uint8_t>::iterator it = nodeAddress.begin() ; it != nodeAddress.end(); ++it)
+ std::vector<uint8_t> netAddress;
+
+ pc.printf("Network Address ");
+ netAddress = dot->getNetworkAddress();
+ for (std::vector<uint8_t>::iterator it = netAddress.begin() ; it != netAddress.end(); ++it)
pc.printf("%2.2x",*it );
pc.printf("\r\n");
@@ -230,15 +230,25 @@
pc.printf("Frequency: %s\r\n", (char*)mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str() );
pc.printf("Sub Band: %s\r\n", (char*)mDot::FrequencySubBandStr(dot->getFrequencySubBand()).c_str() );
pc.printf("Join Mode: %s\r\n", (char*)mDot::JoinModeStr(dot->getJoinMode()).c_str() );
- pc.printf("Join Retries: %d\r\n", (char*)(dot->getJoinByteOrder() == 0 ? "LSB" : "MSB") );
+ pc.printf("Join Retries: %d\r\n", dot->getJoinRetries() );
+ pc.printf("Join Byte Order: %s\r\n", (char*)(dot->getJoinByteOrder() == 0 ? "LSB" : "MSB") );
pc.printf("Link Check Count: %d\r\n", dot->getLinkCheckCount() );
pc.printf("Link Check Thold: %s\r\n", dot->getLinkCheckThreshold() );
pc.printf("Tx Data Rate: %s\r\n", (char*)mDot::DataRateStr(dot->getTxDataRate()).c_str() );
pc.printf("Tx Power: %d\r\n", dot->getTxPower() );
- pc.printf("TxWait: %s, ", (dot->getTxWait() ? "Y" : "N" );
+ pc.printf("TxWait: %s, ", (dot->getTxWait() ? "Y" : "N" ));
pc.printf("CRC: %s, ", (dot->getCrc() ? "Y" : "N") );
pc.printf("Ack: %s\r\n", (dot->getAck() ? "Y" : "N") );
+ logInfo("Joining Network");
+
+ while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) {
+ logError("failed to join network [%d][%s]", ret, mDot::getReturnCodeString(ret).c_str());
+ wait_ms(dot->getNextTxMs() + 1);
+ }
+
+ logInfo("Joined Network");
+
probe.setResolution(9);
char dataBuf[50];