Mbed Client sample for GR-LYCHEE where ZXing is incorporated.
Dependencies: DisplayApp AsciiFont
Fork of GR-PEACH_mbed-os-client-ZXingSample by
Overview
This sample program shows how to use mbed Client together with ZXing which is an open-source, multi-format 1D/2D barcode image processing library. For more info on ZXing, please refer to https://github.com/zxing/zxing.
Required hardware
- GR-LYCHEE ( https://developer.mbed.org/platforms/Renesas-GR-LYCHEE/ )
Application setup
- Select the connection type. For details, please refer to the following wiki:
https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Connection-type. - Set the client credentials. For details, please refer to the following wiki:
https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Client-credentials. - Change Wifi settings. For details, please refer to the following wiki:
https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Wifi-settings.
Building the example
To build this example:
- Import this example onto mbed Compiler.
- Configure the example in accordance with Application setup.
- Compile the example on mbed Compiler and download the resultant binary file.
- Plug the micro-USB cable into the OpenSDA port which lies on the next to the RESET button.
- Copy the binary previously downloaded to your PC to GR-LYCHEE to flash this example. When the copy is successfully completed, the board is ready to work.
- Press the RESET button on the board to run the example.
- For verification, please refer to the following wiki:
https://os.mbed.com/users/1050186/code/GR-LYCHEE_mbed-os-client-ZXingSample/wiki/Monitoring-the-application.
Application resources
This example exposes four resources listed below:
- 3202/0/5700. Decode result of barcode data input from camera (GET).
- 3201/0/5850. Blink function, blinks LED when executed (POST).
- 3201/0/5853. Blink pattern, used by the blink function to determine how to blink. In the format of 1000:500:1000:500:1000:500 (PUT).
- 3201/0/5855. Blink color, used by the blink function. Any of green, yellow, orange and red is acceptable (PUT).
Diff: simpleclient.h
- Revision:
- 2:6ec5c1c1d41c
- Parent:
- 0:eb73febb2bba
- Child:
- 12:7a199eff6988
--- a/simpleclient.h Wed Oct 19 15:58:43 2016 +0900 +++ b/simpleclient.h Tue Mar 28 11:02:34 2017 +0000 @@ -25,11 +25,44 @@ #include "mbed-client/m2mobjectinstance.h" #include "mbed-client/m2mresource.h" #include "mbed-client/m2mconfig.h" +#include "mbed-client/m2mblockmessage.h" #include "security.h" #include "mbed.h" -//Select binding mode: UDP or TCP -M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP; +#define ETHERNET 1 +#define WIFI 2 +#define MESH_LOWPAN_ND 3 +#define MESH_THREAD 4 +#define ATMEL 5 +#define MCR20 6 + +#define STRINGIFY(s) #s + +// Check if using mesh networking, define helper +#if MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND + #define MESH +#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD + #define MESH +#endif + +#if defined (MESH) || (MBED_CONF_LWIP_IPV6_ENABLED==true) + // Mesh is always IPV6 - also WiFi and ETH can be IPV6 if IPV6 is enabled + M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv6; +#else + // Everything else - we assume it's IPv4 + M2MInterface::NetworkStack NETWORK_STACK = M2MInterface::LwIP_IPv4; +#endif + +//Select binding mode: UDP or TCP -- note - Mesh networking is IPv6 UDP ONLY +#ifdef MESH + M2MInterface::BindingMode SOCKET_MODE = M2MInterface::UDP; +#else + // WiFi or Ethernet supports both - TCP by default to avoid + // NAT problems, but UDP will also work - IF you configure + // your network right. + M2MInterface::BindingMode SOCKET_MODE = M2MInterface::TCP; +#endif + // MBED_DOMAIN and MBED_ENDPOINT_NAME come // from the security.h file copied from connector.mbed.com @@ -89,10 +122,9 @@ */ void create_interface(const char *server_address, void *handler=NULL) { - // Randomizing listening port for Certificate mode connectivity + // Randomizing listening port for Certificate mode connectivity _server_address = server_address; - srand(time(NULL)); - uint16_t port = rand() % 65535 + 12345; + uint16_t port = 0; // Network interface will randomize with port 0 // create mDS interface object, this is the base object everything else attaches to _interface = M2MInterfaceFactory::create_interface(*this, @@ -102,7 +134,7 @@ port, // listen port MBED_DOMAIN, // domain string SOCKET_MODE, // binding mode - M2MInterface::LwIP_IPv4, // network stack + NETWORK_STACK, // network stack ""); // context address string const char *binding_mode = (SOCKET_MODE == M2MInterface::UDP) ? "UDP" : "TCP"; printf("\r\nSOCKET_MODE : %s\r\n", binding_mode); @@ -142,9 +174,9 @@ // Add ResourceID's and values to the security ObjectID/ObjectInstance security->set_resource_value(M2MSecurity::M2MServerUri, _server_address); security->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::Certificate); - security->set_resource_value(M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof(SERVER_CERT)); - security->set_resource_value(M2MSecurity::PublicKey, CERT, sizeof(CERT)); - security->set_resource_value(M2MSecurity::Secretkey, KEY, sizeof(KEY)); + security->set_resource_value(M2MSecurity::ServerPublicKey, SERVER_CERT, sizeof(SERVER_CERT) - 1); + security->set_resource_value(M2MSecurity::PublicKey, CERT, sizeof(CERT) - 1); + security->set_resource_value(M2MSecurity::Secretkey, KEY, sizeof(KEY) - 1); } return security; } @@ -214,7 +246,7 @@ void object_unregistered(M2MSecurity */*server_object*/){ trace_printer("Unregistered Object Successfully"); _unregistered = true; - _registered = false; + _registered = false; } /* @@ -284,10 +316,11 @@ */ void value_updated(M2MBase *base, M2MBase::BaseType type) { printf("\r\nPUT Request Received!"); - printf("\r\nName :'%s', \r\nType : '%d' (0 for Object, 1 for Resource), \r\nType : '%s'\r\n", - base->name().c_str(), + printf("\r\nName :'%s', \r\nPath : '%s', \r\nType : '%d' (0 for Object, 1 for Resource), \r\nType : '%s'\r\n", + base->name(), + base->uri_path(), type, - base->resource_type().c_str() + base->resource_type() ); }