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).
easy-connect/easy-connect.h@22:a3cd35c5cff0, 2018-12-18 (annotated)
- Committer:
- 1050186
- Date:
- Tue Dec 18 07:37:37 2018 +0000
- Revision:
- 22:a3cd35c5cff0
- Parent:
- 18:0ab91e767950
Modify README.md file.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| 1050186 | 18:0ab91e767950 | 1 | #ifndef __MAGIC_CONNECT_H__ |
| 1050186 | 18:0ab91e767950 | 2 | #define __MAGIC_CONNECT_H__ |
| 1050186 | 18:0ab91e767950 | 3 | |
| 1050186 | 18:0ab91e767950 | 4 | #include "mbed.h" |
| 1050186 | 18:0ab91e767950 | 5 | |
| 1050186 | 18:0ab91e767950 | 6 | #define ETHERNET 1 |
| 1050186 | 18:0ab91e767950 | 7 | #define WIFI_ESP8266 2 |
| 1050186 | 18:0ab91e767950 | 8 | #define WIFI_BP3595 3 |
| 1050186 | 18:0ab91e767950 | 9 | #define WIFI_ESP32 4 |
| 1050186 | 18:0ab91e767950 | 10 | |
| 1050186 | 18:0ab91e767950 | 11 | #if MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP8266 |
| 1050186 | 18:0ab91e767950 | 12 | #include "ESP8266Interface.h" |
| 1050186 | 18:0ab91e767950 | 13 | |
| 1050186 | 18:0ab91e767950 | 14 | #ifdef MBED_CONF_APP_ESP8266_DEBUG |
| 1050186 | 18:0ab91e767950 | 15 | ESP8266Interface wifi(MBED_CONF_APP_ESP8266_TX, MBED_CONF_APP_ESP8266_RX, MBED_CONF_APP_ESP8266_DEBUG); |
| 1050186 | 18:0ab91e767950 | 16 | #else |
| 1050186 | 18:0ab91e767950 | 17 | ESP8266Interface wifi(MBED_CONF_APP_ESP8266_TX, MBED_CONF_APP_ESP8266_RX); |
| 1050186 | 18:0ab91e767950 | 18 | #endif |
| 1050186 | 18:0ab91e767950 | 19 | |
| 1050186 | 18:0ab91e767950 | 20 | #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_BP3595 |
| 1050186 | 18:0ab91e767950 | 21 | #include "LWIPBP3595Interface.h" |
| 1050186 | 18:0ab91e767950 | 22 | LWIPBP3595Interface wifi; |
| 1050186 | 18:0ab91e767950 | 23 | #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP32 |
| 1050186 | 18:0ab91e767950 | 24 | #include "ESP32Interface.h" |
| 1050186 | 18:0ab91e767950 | 25 | ESP32Interface wifi(MBED_CONF_EASY_CONNECT_WIFI_ESP32_EN, MBED_CONF_EASY_CONNECT_WIFI_ESP32_IO0, MBED_CONF_EASY_CONNECT_WIFI_ESP32_TX, MBED_CONF_EASY_CONNECT_WIFI_ESP32_RX); |
| 1050186 | 18:0ab91e767950 | 26 | #elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET |
| 1050186 | 18:0ab91e767950 | 27 | #include "EthernetInterface.h" |
| 1050186 | 18:0ab91e767950 | 28 | EthernetInterface eth; |
| 1050186 | 18:0ab91e767950 | 29 | #else |
| 1050186 | 18:0ab91e767950 | 30 | #error "No connectivity method chosen. Please add 'config.network-interfaces.value' to your mbed_app.json (see README.md for more information)." |
| 1050186 | 18:0ab91e767950 | 31 | #endif |
| 1050186 | 18:0ab91e767950 | 32 | |
| 1050186 | 18:0ab91e767950 | 33 | // This is address to mbed Device Connector |
| 1050186 | 18:0ab91e767950 | 34 | #define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684" |
| 1050186 | 18:0ab91e767950 | 35 | |
| 1050186 | 18:0ab91e767950 | 36 | #ifdef MBED_CONF_APP_ESP8266_SSID |
| 1050186 | 18:0ab91e767950 | 37 | #define MBED_CONF_APP_WIFI_SSID MBED_CONF_APP_ESP8266_SSID |
| 1050186 | 18:0ab91e767950 | 38 | #endif |
| 1050186 | 18:0ab91e767950 | 39 | |
| 1050186 | 18:0ab91e767950 | 40 | #ifdef MBED_CONF_APP_ESP8266_PASSWORD |
| 1050186 | 18:0ab91e767950 | 41 | #define MBED_CONF_APP_WIFI_PASSWORD MBED_CONF_APP_ESP8266_PASSWORD |
| 1050186 | 18:0ab91e767950 | 42 | #endif |
| 1050186 | 18:0ab91e767950 | 43 | |
| 1050186 | 18:0ab91e767950 | 44 | #ifndef MBED_CONF_APP_WIFI_SECURITY |
| 1050186 | 18:0ab91e767950 | 45 | #define MBED_CONF_APP_WIFI_SECURITY NSAPI_SECURITY_WPA_WPA2 |
| 1050186 | 18:0ab91e767950 | 46 | #endif |
| 1050186 | 18:0ab91e767950 | 47 | |
| 1050186 | 18:0ab91e767950 | 48 | NetworkInterface* easy_connect(bool log_messages = false) { |
| 1050186 | 18:0ab91e767950 | 49 | NetworkInterface* network_interface = 0; |
| 1050186 | 18:0ab91e767950 | 50 | int connect_success = -1; |
| 1050186 | 18:0ab91e767950 | 51 | #if MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP8266 |
| 1050186 | 18:0ab91e767950 | 52 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 53 | printf("[EasyConnect] Using WiFi (ESP8266) \n"); |
| 1050186 | 18:0ab91e767950 | 54 | printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID); |
| 1050186 | 18:0ab91e767950 | 55 | } |
| 1050186 | 18:0ab91e767950 | 56 | connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); |
| 1050186 | 18:0ab91e767950 | 57 | network_interface = &wifi; |
| 1050186 | 18:0ab91e767950 | 58 | #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_BP3595 |
| 1050186 | 18:0ab91e767950 | 59 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 60 | printf("[EasyConnect] Using WiFi (BP3595) \n"); |
| 1050186 | 18:0ab91e767950 | 61 | printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID); |
| 1050186 | 18:0ab91e767950 | 62 | } |
| 1050186 | 18:0ab91e767950 | 63 | connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); |
| 1050186 | 18:0ab91e767950 | 64 | network_interface = &wifi; |
| 1050186 | 18:0ab91e767950 | 65 | #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP32 |
| 1050186 | 18:0ab91e767950 | 66 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 67 | printf("[EasyConnect] Using WiFi (ESP32) \n"); |
| 1050186 | 18:0ab91e767950 | 68 | printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID); |
| 1050186 | 18:0ab91e767950 | 69 | } |
| 1050186 | 18:0ab91e767950 | 70 | connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); |
| 1050186 | 18:0ab91e767950 | 71 | network_interface = &wifi; |
| 1050186 | 18:0ab91e767950 | 72 | #elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET |
| 1050186 | 18:0ab91e767950 | 73 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 74 | printf("[EasyConnect] Using Ethernet\n"); |
| 1050186 | 18:0ab91e767950 | 75 | } |
| 1050186 | 18:0ab91e767950 | 76 | connect_success = eth.connect(); |
| 1050186 | 18:0ab91e767950 | 77 | network_interface = ð |
| 1050186 | 18:0ab91e767950 | 78 | #endif |
| 1050186 | 18:0ab91e767950 | 79 | if(connect_success == 0) { |
| 1050186 | 18:0ab91e767950 | 80 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 81 | printf("[EasyConnect] Connected to Network successfully\n"); |
| 1050186 | 18:0ab91e767950 | 82 | } |
| 1050186 | 18:0ab91e767950 | 83 | } else { |
| 1050186 | 18:0ab91e767950 | 84 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 85 | printf("[EasyConnect] Connection to Network Failed %d!\n", connect_success); |
| 1050186 | 18:0ab91e767950 | 86 | } |
| 1050186 | 18:0ab91e767950 | 87 | return NULL; |
| 1050186 | 18:0ab91e767950 | 88 | } |
| 1050186 | 18:0ab91e767950 | 89 | const char *ip_addr = network_interface->get_ip_address(); |
| 1050186 | 18:0ab91e767950 | 90 | const char *mac_addr = network_interface->get_mac_address(); |
| 1050186 | 18:0ab91e767950 | 91 | if (ip_addr == NULL) { |
| 1050186 | 18:0ab91e767950 | 92 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 93 | printf("[EasyConnect] ERROR - No IP address\n"); |
| 1050186 | 18:0ab91e767950 | 94 | } |
| 1050186 | 18:0ab91e767950 | 95 | return NULL; |
| 1050186 | 18:0ab91e767950 | 96 | } |
| 1050186 | 18:0ab91e767950 | 97 | if (mac_addr == NULL) { |
| 1050186 | 18:0ab91e767950 | 98 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 99 | printf("[EasyConnect] ERROR - No MAC address\n"); |
| 1050186 | 18:0ab91e767950 | 100 | } |
| 1050186 | 18:0ab91e767950 | 101 | return NULL; |
| 1050186 | 18:0ab91e767950 | 102 | } |
| 1050186 | 18:0ab91e767950 | 103 | if (log_messages) { |
| 1050186 | 18:0ab91e767950 | 104 | printf("[EasyConnect] IP address %s\n", ip_addr); |
| 1050186 | 18:0ab91e767950 | 105 | printf("[EasyConnect] MAC address %s\n", mac_addr); |
| 1050186 | 18:0ab91e767950 | 106 | } |
| 1050186 | 18:0ab91e767950 | 107 | return network_interface; |
| 1050186 | 18:0ab91e767950 | 108 | } |
| 1050186 | 18:0ab91e767950 | 109 | |
| 1050186 | 18:0ab91e767950 | 110 | #endif // __MAGIC_CONNECT_H__ |
| 1050186 | 18:0ab91e767950 | 111 |
