Skip to content

Commit

Permalink
Add VFP 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
szilveszterb committed Jan 11, 2016
0 parents commit 87b57ac
Show file tree
Hide file tree
Showing 13 changed files with 7,664 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/projects/EA-WCM-P.X/nbproject/private/
/projects/EA-WCM-P.X/build/default/
/projects/EA-WCM-P.X/dist/default/
/projects/EmbeddedClient-Microchip-WCM.X/build/default/
/projects/EmbeddedClient-Microchip-WCM.X/dist/default/
/projects/EmbeddedClient-Microchip-WCM.X/nbproject/private/
/projects/EmbeddedClient-Microchip-WCM.X/nbproject/Makefile*

.DS_Store
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "er_sdk"]
path = er_sdk
url = https://github.com/exosite-ready/er_sdk.git
[submodule "platforms/er_plat_microchip_wcm"]
path = platforms/er_plat_microchip_wcm
url = https://github.com/exosite-ready/er_plat_microchip_wcm.git
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Summary
This is an Exostie Embedded Client Demo using Microchip's WCM board
For released binaries clone the Release binary repo from git@i.exosite.com:exositeready/er_release_binaries.git
The releases for this device can be found in the microchip_wcm folder

# Demo Description
The demo does the following:
1.) The client will activate the device is not already activated.
If the device config memory does not contain a valid configuration
(i.e after a firmware update) then make sure that the device
is not yet activated, otherwise the activation will fail and
the device won't work
2.) It Checks the state of 4 buttons on the WCM Board (S1..S4) and
sends a notification to the server if a button is pressed.
The notification value is 1 for the 1st button press, 0 for the
next button press, then 0 and so on.

3.) Parallel, it subscribes to the "led" data resource and toggles
four LEDs (D1 .. D4) if it is set on the server side.
The value of "led" contains the (desired) binary encoded states of the
four LEDs, e.g.:
value = 1 turns on 1st led
value = 2 turns on 2nd led
value = 3 turns on 1st and 2nd led
value = 4 turns on 3rd led
value = 5 turns off 1st and 3rd led
value = 6 turns off 2nd and 3rd led
value = 7 turns off 1st, 2nd and 3rd led
value = 8 turns off 4th led

4.) It sends the value of the potentiometer every 5 seconds

# Install and build
This demo application needs Microchip's WCM SDK!!!
This SDK shall be installed to a given path so that the project file in the application can find it!!!
MPLABX and XC32 compiler have to installed separately, the MPLAB installer won't install XC32
XC32 1.34 is needed to build this application!!!

1. git clone https://github.com/exosite-ready/er_vfp_microchip_wcm.git
2. cd er_vfp_microchip_wcm
3. git submodule update --init --recursive
4. Download Microchip's WCM SDK from [WCM Firmware 01.00.00](http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en571775)
5. Install this SDK by unzipping WCM_DK1_01.00.00.zip into a folder named '3rd_party' relative to the ../er_vfp_microchip_wcm folder
Example:
- If the client is cloned to: /opt/er_vfp_microchip_wcm
- Then the WCM DK should be in /opt/3rd_party/WCM_DK1_01.00.00
6. run ./install.sh from the er_vfp_microchip_wcm folder
7. Open the project EmbeddedClient-Microchip-WCM from MPLAB
8. Build and download the firwmare with MPLAB
9. Find detailed instruction on how to Download and use a binary below

# Hardware Setup
1. Connect a PICkit3 to the WCM's "ICSP" connector.
2. Connect a USB cable to the WCM's "J3" connector.
3. (Optional) Connect a USB to TTL UART converter to "J2". J2.GND-GND. J2.RF5-RXD.
3. Turn on power switch ("S5").

# Flashing the Firmware
1. Clone the release binaries repository from git@i.exosite.com:exositeready/er_release_binaries.git
(git clone git@i.exosite.com:exositeready/er_release_binaries.git)
2. Open "MPLAB IPE" v2.35 or greater
3. Select "Device" -> PIC32MX695F512H
4. Press "Connect" button.
5. You should see the message "Connecting to MPLAB PICkit 3..."
6. Press "Browse" button, and choose "er_release_binaries/er_plat_microchip_wcm/vfp/ec_microchip_wcm-x.y.z.hex",
where x.y.z is the version number.
7. Press "Program" button.
8. After programming, WCM D1 will be on; if the board could connect with wifi to an AP D5 will be on, D1 will be off

# Network Setup
1. Connect to the SSID "xxxxxx_WCM", take note of the value of the "xxxxxx" part, you will need it later.
Note: If you SSID does not match this format you'll need to up the WiFi module's firmware.
2. Open web browser, and navigate to http://192.168.1.25
3. Input your AP router information.

# Debug Terminal (Optional):
1. Open serial terminal application with baudrate of 115200.
2. Press WCM S6. Observe MAC information if needed.

# Cloud Setup
1. Go to http://microchip.exosite.com
2. Add a "WCM Development Kit 1" device with its MAC address, the first 6 digits will be auto filled and the last 6 are the "xxxxxx" portion of the SSID you connected to earlier.
3. If the board fails to activate (the following message shows up in the terminal: "Error [-106]: Activate request returned error") you may need to re-enable the client in Portals or press the reset button on the board.

If you see "Error [-107]: Activate request returned error" this means your device was not yet added to the Server; please follow the instructions in Cloud setup: step 1 and 2

# Resetting AP setting
1. Turn off the board
2. Press S1 and keep pressing while turning on the board
3. Turn on the board
4. Keep pressing S1 until D1 is turned on
5. Now you can reconfigure the AP settings with the method in chapter #Network Setup

277 changes: 277 additions & 0 deletions app/exosite_wcm_demo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
/** DESCRIPTION
* -------------------
* This a Demo Application for the Microchip WCM boarad DM182020WCM
*
* 1.) It Checks the state of 4 buttons on the WCM Board (S1..S4) and
* sends a notification to the server if a button is pressed.
* The notification value is 1 for the 1st button press, 0 for the
* next button press, then 0 and so on.
*
* 2.) Parallel, it subscribes to the "led" data resource and toggles
* four LEDs (D1 .. D4) if it is set on the server side.
* The value of "led" contains the (desired) binary encoded states of the
* four LEDs, e.g.:
* value = 1 turns on 1st led
* value = 2 turns on 2nd led
* value = 3 turns on 1st and 2nd led
* value = 4 turns on 3rd led
* value = 5 turns off 1st and 3rd led
* value = 6 turns off 2nd and 3rd led
* value = 7 turns off 1st, 2nd and 3rd led
* value = 8 turns off 4th led
*
* 3.) It sends the value of the potentiometer every second
*
* NOTE: If your device has not been activated, the activation process
* will be performed when this example runs first time. The given CIK will
* be stored in the device's permanent memory. Later this stored CIK
* will be used for the communication.
*
* NOTE: Make sure that your device does not store an invalid CIK in
* its permanent storage. (For example the device was activated before,
* but the assigned device on portal has been deleted).
* If it does, you have to clear it to enforce a new activation process.
*
*/

#include <stdio.h>
#include <lib/type.h>
#include <lib/error.h>
#include <lib/debug.h>
#include <porting/system_port.h>
#include <exosite_api.h>
#include <platform_demo.h>
#include <configurator_api.h>

/**
* Sets the four leds based on a string value
* The string value contains a number, which binary encodes 4 LED states
**/
static void set_leds(char *value)
{
char *endptr;
uint32_t led_value;

led_value = strtol(value, &endptr, 0);
if (endptr == value || *endptr != '\0')
return;

/* LED value demultiplexing
* Values
* 0th bit is led 0
* 1st bit is led 1
* 2nd bit is led 2
* 3rdcbit is led 3
*/
platform_set_led(0, led_value & 0x1);
platform_set_led(1, (led_value >> 1) & 0x1);
platform_set_led(2, (led_value >> 2) & 0x1);
platform_set_led(3, (led_value >> 3) & 0x1);
}

/**
* This function is called when the read operation is finished.
*
* @param[in] status Status of the read operation. It is ERR_SUCCESS
* in case of success. Otherwise it is <0.
* @param[in] alias Alias of the data resource.
* @param[in] value Value of the data resource
*/
static void on_read(int status, const char *alias, const char *value)
{
if (status == ERR_SUCCESS) {
info_log(DEBUG_APPLICATION, ("Read \"%s\": %s\n",alias, value));
set_leds(value);
}
}

/**
* This function is called when the write operation is finished.
*
* @param[in] status Status of the wrire operation. It is ERR_SUCCESS
* in case of success. Otherwise it is <0.
* @param[in] alias Alias of the data resource.
* @param[in] value Value of the data resource
*/
static void on_write(int status, const char *alias)
{
if (status == ERR_SUCCESS)
info_log(DEBUG_APPLICATION,("Write \"%s\"\n",alias));
}

/**
* This function is called when the data resource changed on the server.
*
* @param[in] status Status of the read operation. It is ERR_SUCCESS
* in case of success. Otherwise it is <0.
* @param[in] alias Alias of the data resource.
* @param[in] value Value of the data resource
*/
static void on_change(int status, const char *alias, const char *value)
{
if (status == ERR_SUCCESS) {
info_log(DEBUG_APPLICATION,("Value changed on server \"%s\" to %s \n",alias, value));
set_leds(value);
}
}

#define NUMBER_OF_BUTTONS 4
/**
* This function looks for a 0 - 1 transition in the state of button[i]
* Button id 0 - 3 identifies the buttons S1..S4
* If it founds a 0 - 1 transition it return TRUE otherwise it returns FALSE
*
**/
static BOOL detect_edge(int button)
{
static BOOL button_state[NUMBER_OF_BUTTONS];
static BOOL previous_button_state[NUMBER_OF_BUTTONS] = {FALSE, FALSE, FALSE, FALSE};
static BOOL leading_edge[NUMBER_OF_BUTTONS] = {FALSE, FALSE, FALSE, FALSE};

platform_get_switch(button, &button_state[button]);
if (previous_button_state[button] == FALSE && button_state[button] == TRUE)
leading_edge[button] = TRUE;
else
leading_edge[button] = FALSE;

if (button_state[button] != previous_button_state[button])
previous_button_state[button] = button_state[button];

if (leading_edge[button] == TRUE)
return TRUE;

return FALSE;
}
/**
* Entry point of the demo
*/

#define MAX_VALUE_SIZE 16

volatile BOOL wifi_parameters_set;

static int32_t on_new_wifi_config(struct wifi_settings *wifi_cfg)
{
struct sNetworkParams params;
int32_t error;

info_log(DEBUG_APPLICATION,
("New WiFi Config (SSID: %s; Security: %s; Pass: %s)\n",
wifi_cfg->ssid,
(wifi_cfg->security == WPA2) ? "WPA2" : (wifi_cfg->security == OPEN) ? "OPEN" : "Unknown",
wifi_cfg->passpharase));

params.SSID = wifi_cfg->ssid;
params.PASSW = wifi_cfg->passpharase;
error = platform_save_network_configuration(&params);
wifi_parameters_set = TRUE;

return error;
}

int main()
{
struct exosite_class *exo = NULL;
int error;
int i;
BOOL wifi_configured;
struct sNetworkParams params;
char * switch_alias[] = {"sw1", "sw2", "sw3", "sw4"};
char potmeter_value_str[MAX_VALUE_SIZE];
sys_time_t start_time;
struct platform_init_class pl_init;
enum exosite_device_status status;

/** 1. Initialize the platform and configure and join the network */
platform_init(&pl_init);
/* Platform specific wifi configuration
* PLATFORM_SPECIFIC_WIFI_CONFIG has to be set
* This demo will use the wifi config method from
* WCM DK
* */
platform_set_led(0, TRUE);

/** 2. Initialize the Exosite Ready SDK */
/** SDK init needs to be done before the configurator server is started */
exosite_sdk_init(platform_get_debug_printf(), NULL);

/**
* 3. Register the platform specific periodic function
* @note It is necessary only if this is a non-threading system
* and there is a periodic task you have to call
*/
exosite_sdk_register_periodic_fn(pl_init.platform_periodic_fn, pl_init.platform_fn_period);

wifi_configured = platform_is_network_configured();
if (!wifi_configured) {
platform_connect_ap_mode();
/* This is the IP address of WCM board when started in server mode */
start_configurator_server("192.168.1.25", 80, NULL, on_new_wifi_config);

while (!wifi_parameters_set) {
exosite_delay_and_poll(exo, 50);
}
/*
* We should wait until the response is sent to the browser
* This is platform dependent so the application can decide how much to wait here
*
**/
info_log(DEBUG_APPLICATION, ("Wait for before reset\n"));
exosite_delay_and_poll(exo, 1000);
info_log(DEBUG_APPLICATION, ("Perform reset\n"));
info_log(DEBUG_APPLICATION, ("-------------\n"));
platform_reset();
}

error = platform_get_network_configuration(&params);
if (error)
return;

error = platform_join_network(&params);
if (error)
return;

/** 4. Instantiate the Exosite object */
error = exosite_new(&exo, "microchip", "dm182020wcm", NULL, APP_PROTO_HTTP);
if (error)
return;

/** 5. Wait for the device activation */
do {
status = exosite_get_status(exo);
exosite_delay_and_poll(exo, 200);
} while (status != DEVICE_STATUS_ACTIVATED);

/** 6. Subscribe to the "led" data source */
error = exosite_subscribe(exo, "led", 0, on_change);
if (error)
return error;

/** 7. Synchronize data sources with the server */
exosite_read(exo, "led", on_read);

start_time = system_get_time();
/**
* 8. In an infinite loop the app checks for
* - button press
* - sends the potmeter value at every 5 seconds
*/
while (1) {
for (i = 0; i < NUMBER_OF_BUTTONS; i++) {
if (detect_edge(i) == TRUE) {
info_log(DEBUG_NET, ("Button %d pressed\n", i));
exosite_write(exo, switch_alias[i], "1", on_write);
}
}

if (system_get_diff_time(start_time) > 5000) {
start_time = system_get_time();
platform_get_sensor_value(EXO_POTMETER, 0, potmeter_value_str, MAX_VALUE_SIZE);
info_log(DEBUG_NET, ("Send potmeter value: %s\n", potmeter_value_str));
exosite_write(exo, "pot", potmeter_value_str, on_write);
}

exosite_delay_and_poll(NULL, 10);
}

}
Loading

0 comments on commit 87b57ac

Please sign in to comment.