Skip to content

Commit

Permalink
Fixed sensor address
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed May 12, 2019
1 parent 3b8c71c commit 4b8281f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .vscode/bookmarks.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,15 @@
"label": ""
}
]
},
{
"path": "$ROOTPATH$/repos/apache-mynewt-core/encoding/tinycbor/src/cborencoder.c",
"bookmarks": [
{
"line": 241,
"column": 17,
"label": ""
}
]
}
]
6 changes: 3 additions & 3 deletions libs/sensor_coap/src/sensor_coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
*/
// Post sensor data to CoAP server with JSON or CBOR encoding. We call the Mynewt OIC
// interface to encode and transmit CoAP messages. For ESP8266, the OIC interface
// is implemented by esp8266/transport.h. This is a simpler version of oc_client_api
// Post sensor data to CoAP Server or Collector Node with JSON or CBOR encoding. We call the Mynewt OIC
// interface to encode and transmit CoAP messages. For ESP8266 and nRF24L01, the OIC interface
// is implemented by esp8266/transport.h and nrf24l01/transport.h. This is a simpler version of oc_client_api
// that supports sensors and JSON. Original version: repos\apache-mynewt-core\net\oic\src\api\oc_client_api.c

#include <os/mynewt.h>
Expand Down
17 changes: 7 additions & 10 deletions libs/sensor_network/src/sensor_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ static int sensor_network_encoding[MAX_INTERFACE_TYPES] = {
APPLICATION_JSON, // Send to Server: JSON encoding for payload
APPLICATION_CBOR, // Send to Collector: CBOR encoding for payload
};
static const char *sensor_network_shortname[MAX_INTERFACE_TYPES] = {
"svr",
"col",
};

int sensor_network_register_interface(const struct sensor_network_interface *iface) {
// Register the Network Interface (e.g. ESP8266, nRF24L01) for the Sensor Network.
Expand All @@ -109,7 +113,7 @@ int sensor_network_register_interface(const struct sensor_network_interface *ifa
assert(sensor_network_interfaces[i].network_device == NULL); // Interface already registered.
memcpy(&sensor_network_interfaces[i], iface, sizeof(struct sensor_network_interface)); // Copy the interface.
sensor_network_interfaces[i].transport_registered = 0; // We defer the registration of the transport till first use.
console_printf("SN %s %s\n", (i == 0) ? "svr" : "col", sensor_network_interfaces[i].network_device);
console_printf("SN %s %s\n", sensor_network_shortname[i], sensor_network_interfaces[i].network_device);
return 0;
}

Expand Down Expand Up @@ -156,7 +160,7 @@ int sensor_network_register_transport(uint8_t iface_type) {
// If endpoint has not been created, register the transport for the interface and create the endpoint.
assert(iface->network_device); assert(iface->register_transport_func);
const char *network_device = iface->network_device;
console_printf("TRN %s %s\n", (iface_type == 0) ? "svr" : "col", network_device);
console_printf("TRN %s %s\n", sensor_network_shortname[iface_type], network_device);

// TODO: Host and port are not needed for Collector.
int rc = iface->register_transport_func(network_device, endpoint, COAP_HOST, MYNEWT_VAL(COAP_PORT), MAX_ENDPOINT_SIZE);
Expand Down Expand Up @@ -230,14 +234,7 @@ bool is_collector_node(void) {
bool is_sensor_node(void) {
// Return true if this is a Sensor Node.
// This is a Sensor Node if the Hardware ID matches one of the Sensor Node Hardware IDs.
const uint8_t *hardware_id = get_hardware_id();
int i;
for (i = 0; i < SENSOR_NETWORK_SIZE; i++) {
if (memcmp(hardware_id, SENSOR_NODE_HW_IDS[i], HARDWARE_ID_LENGTH) == 0) {
console_printf("*** sensor node %d\n", i + 1);
return true;
}
}
if (sensor_node_address) { return true; } // sensor_node_address is set in sensor_network_init().
return false;
}

Expand Down

0 comments on commit 4b8281f

Please sign in to comment.