This is a mbed Client sample where ZXing is incorporated, and works on GR-PEACH and GR-LYCHEE.
Dependencies: DisplayApp AsciiFont
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-PEACH ( https://developer.mbed.org/platforms/Renesas-GR-PEACH/ )
- Audio Camera Shield ( https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield )
- LCD Shield ( https://developer.mbed.org/teams/Renesas/wiki/LCD-shield )
- Ethernet cable and connection to the internet
- Wireless Camera shieled (This is GR-PEACH' Wifi(ESP32) optional.)
- 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/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Connection-type. - Set the client credentials. For details, please refer to the following wiki:
https://os.mbed.com/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Client-credentials. - Change Ethernet settings. For details, please refer to the following wiki:
https://developer.mbed.org/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Ethernet-settings. - Change Wifi settings. For details, please refer to the following wiki:
https://os.mbed.com/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/Wifi-settings. - Set up an IP address. (This step is optional.) For details, please refer to the following wiki:
https://os.mbed.com/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/wiki/IP-address-setup.
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 Ethernet cable into GR-PEACH or GR-LYCHEE if you are using Ethernet mode.
- 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-PEACH or 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://developer.mbed.org/teams/Renesas/code/GR-PEACH_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 red, green, blue, cyan, yellow and magenta is acceptable if you are using GR-PEACH board (PUT).
- 3201/0/5855. Blink color, used by the blink function. Any of green, yellow, orange and red is acceptable if you are using GR-LYCHEE board (PUT).
For more info on how to get notifications when resource 1 changes, or how to use resource 2, 3 and 4, please look at
Import programGR-PEACH_mbed-connector-ZXingSample-node
Node.js based Web Application for mbed Device Connector specific to GR-PEACH_mbed-os-client-ZXingSample
easy-connect/easy-connect.h@10:f7e8d2b608c3, 2018-12-13 (annotated)
- Committer:
- 1050186
- Date:
- Thu Dec 13 09:17:41 2018 +0000
- Revision:
- 10:f7e8d2b608c3
- Parent:
- 7:f9c1728de5c5
Delete unnecessary code.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
1050186 | 7:f9c1728de5c5 | 1 | #ifndef __MAGIC_CONNECT_H__ |
1050186 | 7:f9c1728de5c5 | 2 | #define __MAGIC_CONNECT_H__ |
1050186 | 7:f9c1728de5c5 | 3 | |
1050186 | 7:f9c1728de5c5 | 4 | #include "mbed.h" |
1050186 | 7:f9c1728de5c5 | 5 | |
1050186 | 7:f9c1728de5c5 | 6 | #define ETHERNET 1 |
1050186 | 7:f9c1728de5c5 | 7 | #define WIFI_ESP8266 2 |
1050186 | 7:f9c1728de5c5 | 8 | #define WIFI_BP3595 3 |
1050186 | 7:f9c1728de5c5 | 9 | #define WIFI_ESP32 4 |
1050186 | 7:f9c1728de5c5 | 10 | |
1050186 | 7:f9c1728de5c5 | 11 | #if MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP8266 |
1050186 | 7:f9c1728de5c5 | 12 | #include "ESP8266Interface.h" |
1050186 | 7:f9c1728de5c5 | 13 | |
1050186 | 7:f9c1728de5c5 | 14 | #ifdef MBED_CONF_APP_ESP8266_DEBUG |
1050186 | 7:f9c1728de5c5 | 15 | ESP8266Interface wifi(MBED_CONF_APP_ESP8266_TX, MBED_CONF_APP_ESP8266_RX, MBED_CONF_APP_ESP8266_DEBUG); |
1050186 | 7:f9c1728de5c5 | 16 | #else |
1050186 | 7:f9c1728de5c5 | 17 | ESP8266Interface wifi(MBED_CONF_APP_ESP8266_TX, MBED_CONF_APP_ESP8266_RX); |
1050186 | 7:f9c1728de5c5 | 18 | #endif |
1050186 | 7:f9c1728de5c5 | 19 | |
1050186 | 7:f9c1728de5c5 | 20 | #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_BP3595 |
1050186 | 7:f9c1728de5c5 | 21 | #include "LWIPBP3595Interface.h" |
1050186 | 7:f9c1728de5c5 | 22 | LWIPBP3595Interface wifi; |
1050186 | 7:f9c1728de5c5 | 23 | #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP32 |
1050186 | 7:f9c1728de5c5 | 24 | #include "ESP32Interface.h" |
1050186 | 7:f9c1728de5c5 | 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 | 7:f9c1728de5c5 | 26 | #elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET |
1050186 | 7:f9c1728de5c5 | 27 | #include "EthernetInterface.h" |
1050186 | 7:f9c1728de5c5 | 28 | EthernetInterface eth; |
1050186 | 7:f9c1728de5c5 | 29 | #else |
1050186 | 7:f9c1728de5c5 | 30 | #error "No connectivity method chosen. Please add 'config.network-interfaces.value' to your mbed_app.json (see README.md for more information)." |
1050186 | 7:f9c1728de5c5 | 31 | #endif |
1050186 | 7:f9c1728de5c5 | 32 | |
1050186 | 7:f9c1728de5c5 | 33 | // This is address to mbed Device Connector |
1050186 | 7:f9c1728de5c5 | 34 | #define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684" |
1050186 | 7:f9c1728de5c5 | 35 | |
1050186 | 7:f9c1728de5c5 | 36 | #ifdef MBED_CONF_APP_ESP8266_SSID |
1050186 | 7:f9c1728de5c5 | 37 | #define MBED_CONF_APP_WIFI_SSID MBED_CONF_APP_ESP8266_SSID |
1050186 | 7:f9c1728de5c5 | 38 | #endif |
1050186 | 7:f9c1728de5c5 | 39 | |
1050186 | 7:f9c1728de5c5 | 40 | #ifdef MBED_CONF_APP_ESP8266_PASSWORD |
1050186 | 7:f9c1728de5c5 | 41 | #define MBED_CONF_APP_WIFI_PASSWORD MBED_CONF_APP_ESP8266_PASSWORD |
1050186 | 7:f9c1728de5c5 | 42 | #endif |
1050186 | 7:f9c1728de5c5 | 43 | |
1050186 | 7:f9c1728de5c5 | 44 | #ifndef MBED_CONF_APP_WIFI_SECURITY |
1050186 | 7:f9c1728de5c5 | 45 | #define MBED_CONF_APP_WIFI_SECURITY NSAPI_SECURITY_WPA_WPA2 |
1050186 | 7:f9c1728de5c5 | 46 | #endif |
1050186 | 7:f9c1728de5c5 | 47 | |
1050186 | 7:f9c1728de5c5 | 48 | NetworkInterface* easy_connect(bool log_messages = false) { |
1050186 | 7:f9c1728de5c5 | 49 | NetworkInterface* network_interface = 0; |
1050186 | 7:f9c1728de5c5 | 50 | int connect_success = -1; |
1050186 | 7:f9c1728de5c5 | 51 | #if MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP8266 |
1050186 | 7:f9c1728de5c5 | 52 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 53 | printf("[EasyConnect] Using WiFi (ESP8266) \n"); |
1050186 | 7:f9c1728de5c5 | 54 | printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID); |
1050186 | 7:f9c1728de5c5 | 55 | } |
1050186 | 7:f9c1728de5c5 | 56 | connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); |
1050186 | 7:f9c1728de5c5 | 57 | network_interface = &wifi; |
1050186 | 7:f9c1728de5c5 | 58 | #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_BP3595 |
1050186 | 7:f9c1728de5c5 | 59 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 60 | printf("[EasyConnect] Using WiFi (BP3595) \n"); |
1050186 | 7:f9c1728de5c5 | 61 | printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID); |
1050186 | 7:f9c1728de5c5 | 62 | } |
1050186 | 7:f9c1728de5c5 | 63 | connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); |
1050186 | 7:f9c1728de5c5 | 64 | network_interface = &wifi; |
1050186 | 7:f9c1728de5c5 | 65 | #elif MBED_CONF_APP_NETWORK_INTERFACE == WIFI_ESP32 |
1050186 | 7:f9c1728de5c5 | 66 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 67 | printf("[EasyConnect] Using WiFi (ESP32) \n"); |
1050186 | 7:f9c1728de5c5 | 68 | printf("[EasyConnect] Connecting to WiFi %s\n", MBED_CONF_APP_WIFI_SSID); |
1050186 | 7:f9c1728de5c5 | 69 | } |
1050186 | 7:f9c1728de5c5 | 70 | connect_success = wifi.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD, MBED_CONF_APP_WIFI_SECURITY); |
1050186 | 7:f9c1728de5c5 | 71 | network_interface = &wifi; |
1050186 | 7:f9c1728de5c5 | 72 | #elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET |
1050186 | 7:f9c1728de5c5 | 73 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 74 | printf("[EasyConnect] Using Ethernet\n"); |
1050186 | 7:f9c1728de5c5 | 75 | } |
1050186 | 7:f9c1728de5c5 | 76 | connect_success = eth.connect(); |
1050186 | 7:f9c1728de5c5 | 77 | network_interface = ð |
1050186 | 7:f9c1728de5c5 | 78 | #endif |
1050186 | 7:f9c1728de5c5 | 79 | if(connect_success == 0) { |
1050186 | 7:f9c1728de5c5 | 80 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 81 | printf("[EasyConnect] Connected to Network successfully\n"); |
1050186 | 7:f9c1728de5c5 | 82 | } |
1050186 | 7:f9c1728de5c5 | 83 | } else { |
1050186 | 7:f9c1728de5c5 | 84 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 85 | printf("[EasyConnect] Connection to Network Failed %d!\n", connect_success); |
1050186 | 7:f9c1728de5c5 | 86 | } |
1050186 | 7:f9c1728de5c5 | 87 | return NULL; |
1050186 | 7:f9c1728de5c5 | 88 | } |
1050186 | 7:f9c1728de5c5 | 89 | const char *ip_addr = network_interface->get_ip_address(); |
1050186 | 7:f9c1728de5c5 | 90 | const char *mac_addr = network_interface->get_mac_address(); |
1050186 | 7:f9c1728de5c5 | 91 | if (ip_addr == NULL) { |
1050186 | 7:f9c1728de5c5 | 92 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 93 | printf("[EasyConnect] ERROR - No IP address\n"); |
1050186 | 7:f9c1728de5c5 | 94 | } |
1050186 | 7:f9c1728de5c5 | 95 | return NULL; |
1050186 | 7:f9c1728de5c5 | 96 | } |
1050186 | 7:f9c1728de5c5 | 97 | if (mac_addr == NULL) { |
1050186 | 7:f9c1728de5c5 | 98 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 99 | printf("[EasyConnect] ERROR - No MAC address\n"); |
1050186 | 7:f9c1728de5c5 | 100 | } |
1050186 | 7:f9c1728de5c5 | 101 | return NULL; |
1050186 | 7:f9c1728de5c5 | 102 | } |
1050186 | 7:f9c1728de5c5 | 103 | if (log_messages) { |
1050186 | 7:f9c1728de5c5 | 104 | printf("[EasyConnect] IP address %s\n", ip_addr); |
1050186 | 7:f9c1728de5c5 | 105 | printf("[EasyConnect] MAC address %s\n", mac_addr); |
1050186 | 7:f9c1728de5c5 | 106 | } |
1050186 | 7:f9c1728de5c5 | 107 | return network_interface; |
1050186 | 7:f9c1728de5c5 | 108 | } |
1050186 | 7:f9c1728de5c5 | 109 | |
1050186 | 7:f9c1728de5c5 | 110 | #endif // __MAGIC_CONNECT_H__ |
1050186 | 7:f9c1728de5c5 | 111 |