Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DS1820 libmDot mbed-rtos mbed
Diff: main.cpp
- Revision:
- 7:2a704d1a30e1
- Parent:
- 6:0a7760eeaba9
- Child:
- 8:8070e9d660e4
--- a/main.cpp Wed Oct 21 23:12:33 2015 +0000
+++ b/main.cpp Wed Oct 28 11:06:03 2015 +0000
@@ -90,8 +90,6 @@
// Test if we've already saved the config
std::string configNetworkName = dot->getNetworkName();
-// config_network_name = std::string(NwkSKey,16);
-// config_network_pass = std::string(NwkSKey,16);
// pc.printf("Name: %s\r\n",config_network_name.c_str());
uint8_t *it = NwkSKey;
@@ -117,18 +115,9 @@
// 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) {
- logError("failed to set Public Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
- }
-
- logInfo("Set MANUAL Join mode");
-// if ((ret = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) {
- if((ret = dot->setJoinMode(mDot::MANUAL)) != mDot::MDOT_OK) {
- logError("Failed to set MANUAL Join Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
- }
+// dot->setCrc(true);
// If on developer board then you can enable activity LED
// Currently no spare pins that LEDs are connected too.
@@ -136,10 +125,10 @@
// dot->setActivityLedEnable(false);
// Have a decent nubmer of retries in connecting to LoRaWAN
- logInfo("Set Join retries");
- if((ret = dot->setJoinRetries( 3 )) != mDot::MDOT_OK) {
- logError("Failed to set Join retries %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
- }
+// logInfo("Set Join retries");
+// if((ret = dot->setJoinRetries( 3 )) != mDot::MDOT_OK) {
+// logError("Failed to set Join retries %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+// }
// Set Spreading Factor, higher is lower data rate, smaller packets but longer range
// Lower is higher data rate, larger packets and shorter range.
@@ -154,6 +143,16 @@
logError("Failed to set Tx Power %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
+ logInfo("Set Public mode");
+ if((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) {
+ logError("failed to set Public Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+ }
+
+ logInfo("Set MANUAL Join mode");
+ if((ret = dot->setJoinMode(mDot::MANUAL)) != mDot::MDOT_OK) {
+ logError("Failed to set MANUAL Join Mode %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+ }
+
logInfo("Set Ack");
// 1 retries on Ack, 0 to disable
if((ret = dot->setAck( 0 )) != mDot::MDOT_OK) {
@@ -168,7 +167,12 @@
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());
+ logError("Failed to set Network Address %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
+ }
+
+ logInfo("Set Data Session Key");
+ if ((ret = dot->setDataSessionKey(nwkSKey)) != mDot::MDOT_OK) {
+ logError("Failed to set Data Session Key %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
logInfo("Set Network Session Key");
@@ -176,11 +180,6 @@
logError("Failed to set Network Session Key %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
- logInfo("Set Data Session Key");
- if ((ret = dot->setDataSessionKey(nwkSKey)) != mDot::MDOT_OK) {
- logError("Failed to set Data Session Key %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
- }
-
// if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
// logError("failed to set network name %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
// }
@@ -233,21 +232,21 @@
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("Link Check Thold: %d\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("CRC: %s, ", (dot->getCrc() ? "Y" : "N") );
pc.printf("Ack: %s\r\n", (dot->getAck() ? "Y" : "N") );
- logInfo("Joining Network");
+// 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);
- }
+// 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");
+// logInfo("Joined Network");
probe.setResolution(9);
@@ -257,9 +256,9 @@
probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready
// printf("It is %3.1fC\r\n", probe.temperature());
- // Output data as JSON e.g. {"tmp":21.3}
+ // Output data as JSON e.g. {"t":21.3}
temperature = probe.temperature();
- sprintf(dataBuf, "{\"tmp\":%3.1f}", temperature );
+ sprintf(dataBuf, "{\"t\":%3.1f}", temperature );
send_data.clear();
// probably not the most efficent way to do this
for( int i=0; i< strlen(dataBuf); i++ )