Kedar Sovani
Published © MIT

Twitter Voter

Deciding a cuisine when going out is a pain, especially when it's a big group. How about a cloud connected ballot ?

IntermediateFull instructions provided840
Twitter Voter

Things used in this project

Story

Read more

Schematics

No Additional Hardware Required

Code

Application Code

C/C++
This is the application code that goes on the MW302 board
/*
 *  Copyright (C) 2008-2015, Marvell International Ltd.
 *  All Rights Reserved.
 */
/*
 *
 * The serial console is set on UART-0.
 *
 * A serial terminal program like HyperTerminal, putty, or
 * minicom can be used to see the program output.
 */

#include <wm_os.h>
#include <wmstdio.h>
#include <wmtime.h>
#include <wmsdk.h>
#include <led_indicator.h>
#include <board.h>
#include <push_button.h>
#include <aws_iot_mqtt_interface.h>
#include <aws_iot_shadow_interface.h>
#include <aws_utils.h>
/* configuration parameters */
#include <aws_iot_config.h>

#include "aws_starter_root_ca_cert.h"

enum state {
	AWS_CONNECTED = 1,
	AWS_RECONNECTED,
	AWS_DISCONNECTED
};

/*-----------------------Global declarations----------------------*/

/* These hold each pushbutton's count, updated in the callback ISR */
static volatile uint32_t pushbutton_a_count;
static volatile uint32_t pushbutton_a_count_prev = -1;
static volatile uint32_t pushbutton_b_count;
static volatile uint32_t pushbutton_b_count_prev = -1;
static volatile uint32_t pushbutton_c_count;
static volatile uint32_t pushbutton_c_count_prev = -1;
static volatile uint32_t pushbutton_d_count;
static volatile uint32_t pushbutton_d_count_prev = -1;


static volatile uint32_t led_1_state;
static volatile uint32_t led_1_state_prev = -1;

static output_gpio_cfg_t led_1;
static MQTTClient_t mqtt_client;
static enum state device_state;

/* Thread handle */
static os_thread_t aws_starter_thread;
/* Buffer to be used as stack */
static os_thread_stack_define(aws_starter_stack, 8 * 1024);
/* Thread handle */
static os_thread_t aws_shadow_yield_thread;
/* Buffer to be used as stack */
static os_thread_stack_define(aws_shadow_yield_stack, 2 * 1024);
/* aws iot url */
static char url[128];

#define MICRO_AP_SSID                "aws_starter"
#define MICRO_AP_PASSPHRASE          "marvellwm"
#define AMAZON_ACTION_BUF_SIZE  100
#define VAR_LED_1_PROPERTY      "led"
#define VAR_BUTTON_A_PROPERTY   "mexican"
#define VAR_BUTTON_B_PROPERTY   "italian"
#define VAR_BUTTON_C_PROPERTY   "indian"
#define VAR_BUTTON_D_PROPERTY   "pizza"
#define RESET_TO_FACTORY_TIMEOUT 5000
#define BUFSIZE                  128

/* callback function invoked on reset to factory */
static void device_reset_to_factory_cb()
{
	/* Clears device configuration settings from persistent memory
	 * and reboots the device.
	 */
	invoke_reset_to_factory();
}

/* board_button_2() is configured to perform reset to factory,
 * when pressed for more than 5 seconds.
 */
static void configure_reset_to_factory()
{
	input_gpio_cfg_t pushbutton_reset_to_factory = {
		.gpio = board_button_2(),
		.type = GPIO_ACTIVE_LOW
	};
	push_button_set_cb(pushbutton_reset_to_factory,
			   device_reset_to_factory_cb,
			   RESET_TO_FACTORY_TIMEOUT, 0, NULL);
}

/* callback function invoked when pushbutton_a is pressed */
static void pushbutton_a_cb()
{
	if (pushbutton_a_count_prev == pushbutton_a_count)
		pushbutton_a_count++;
}

/* callback function invoked when pushbutton_b is pressed */
static void pushbutton_b_cb()
{
	if (pushbutton_b_count_prev == pushbutton_b_count)
		pushbutton_b_count++;
}

static void pushbutton_c_cb()
{
	if (pushbutton_c_count_prev == pushbutton_c_count)
		pushbutton_c_count++;
}

static void pushbutton_d_cb()
{
	if (pushbutton_d_count_prev == pushbutton_d_count)
		pushbutton_d_count++;
}


/* Configure led and pushbuttons with callback functions */
static void configure_led_and_button()
{
	/* respective GPIO pins for pushbuttons and leds are defined in
	 * board file.
	 */
	input_gpio_cfg_t pushbutton_a = {
		.gpio = board_button_1(),
		.type = GPIO_ACTIVE_LOW
	};
	input_gpio_cfg_t pushbutton_b = {
		.gpio = board_button_2(),
		.type = GPIO_ACTIVE_LOW
	};
	input_gpio_cfg_t pushbutton_c = {
		.gpio = board_button_3(),
		.type = GPIO_ACTIVE_LOW
	};
	input_gpio_cfg_t pushbutton_d = {
		.gpio = board_button_4(),
		.type = GPIO_ACTIVE_LOW
	};

	led_1 = board_led_1();

	push_button_set_cb(pushbutton_a,
			   pushbutton_a_cb,
			   100, 0, NULL);
	push_button_set_cb(pushbutton_b,
			   pushbutton_b_cb,
			   100, 0, NULL);
	push_button_set_cb(pushbutton_c,
				 pushbutton_c_cb,
				 100, 0, NULL);
	push_button_set_cb(pushbutton_d,
				 pushbutton_d_cb,
				 100, 0, NULL);

}

static char client_cert_buffer[AWS_PUB_CERT_SIZE];
static char private_key_buffer[AWS_PRIV_KEY_SIZE];
#define THING_LEN 126
#define REGION_LEN 16
static char thing_name[THING_LEN];

/* populate aws shadow configuration details */
static int aws_starter_load_configuration(ShadowParameters_t *sp)
{
	int ret = WM_SUCCESS;
	char region[REGION_LEN];
	memset(region, 0, sizeof(region));

	/* read configured thing name from the persistent memory */
	ret = read_aws_thing(thing_name, THING_LEN);
	if (ret == WM_SUCCESS) {
		sp->pMyThingName = thing_name;
	} else {
		/* if not found in memory, take the default thing name */
		sp->pMyThingName = AWS_IOT_MY_THING_NAME;
	}
	sp->pMqttClientId = AWS_IOT_MQTT_CLIENT_ID;

	/* read configured region name from the persistent memory */
	ret = read_aws_region(region, REGION_LEN);
	if (ret == WM_SUCCESS) {
		snprintf(url, sizeof(url), "data.iot.%s.amazonaws.com",
			 region);
	} else {
		snprintf(url, sizeof(url), "data.iot.%s.amazonaws.com",
			 AWS_IOT_MY_REGION_NAME);
	}
	sp->pHost = url;
	sp->port = AWS_IOT_MQTT_PORT;
	sp->pRootCA = rootCA;

	/* read configured certificate from the persistent memory */
	ret = read_aws_certificate(client_cert_buffer, AWS_PUB_CERT_SIZE);
	if (ret != WM_SUCCESS) {
		wmprintf("Failed to configure certificate. Returning!\r\n");
		return -WM_FAIL;
	}
	sp->pClientCRT = client_cert_buffer;

	/* read configured private key from the persistent memory */
	ret = read_aws_key(private_key_buffer, AWS_PRIV_KEY_SIZE);
	if (ret != WM_SUCCESS) {
		wmprintf("Failed to configure key. Returning!\r\n");
		return -WM_FAIL;
	}
	sp->pClientKey = private_key_buffer;

	return ret;
}

void shadow_update_status_cb(const char *pThingName, ShadowActions_t action,
			     Shadow_Ack_Status_t status,
			     const char *pReceivedJsonDocument,
			     void *pContextData) {

	if (status == SHADOW_ACK_TIMEOUT) {
		wmprintf("Shadow publish state change timeout occurred\r\n");
	} else if (status == SHADOW_ACK_REJECTED) {
		wmprintf("Shadow publish state change rejected\r\n");
	} else if (status == SHADOW_ACK_ACCEPTED) {
		wmprintf("Shadow publish state change accepted\r\n");
	}
}

/* shadow yield thread which periodically checks for data */
static void aws_shadow_yield(os_thread_arg_t data)
{
	while (1) {
		/* periodically check if any data is received on socket */
		aws_iot_shadow_yield(&mqtt_client, 500);
	}
}

/* create shadow yield thread */
static int aws_create_shadow_yield_thread()
{
	int ret;
	ret = os_thread_create(
		/* thread handle */
		&aws_shadow_yield_thread,
		/* thread name */
		"awsShadowYield",
		/* entry function */
		aws_shadow_yield,
		/* argument */
		0,
		/* stack */
		&aws_shadow_yield_stack,
		/* priority */
		OS_PRIO_3);
	if (ret != WM_SUCCESS) {
		wmprintf("Failed to create shadow yield thread: %d\r\n", ret);
		return -WM_FAIL;
	}
	return WM_SUCCESS;
}

/* This function will get invoked when led state change request is received */
void led_indicator_cb(const char *p_json_string,
		      uint32_t json_string_datalen,
		      jsonStruct_t *p_context) {
	int state;
	if (p_context != NULL) {
		state = *(int *)(p_context->pData);
		if (state) {
			led_on(led_1);
			led_1_state = 1;
		} else {
			led_off(led_1);
			led_1_state = 0;
		}
	}
}

/* Publish thing state to shadow */
int aws_publish_property_state(ShadowParameters_t *sp)
{
	char buf_out[BUFSIZE];
	char state[BUFSIZE];
	char *ptr = state;
	int ret = WM_SUCCESS;

	memset(state, 0, BUFSIZE);
	if (pushbutton_a_count_prev != pushbutton_a_count) {
		snprintf(buf_out, BUFSIZE, ",\"%s\":%d", VAR_BUTTON_A_PROPERTY,
			 pushbutton_a_count);
		strcat(state, buf_out);
		pushbutton_a_count_prev = pushbutton_a_count;
	}
	if (pushbutton_b_count_prev != pushbutton_b_count) {
		snprintf(buf_out, BUFSIZE, ",\"%s\":%d", VAR_BUTTON_B_PROPERTY,
			 pushbutton_b_count);
		strcat(state, buf_out);
		pushbutton_b_count_prev = pushbutton_b_count;
	}
	if (pushbutton_c_count_prev != pushbutton_c_count) {
		snprintf(buf_out, BUFSIZE, ",\"%s\":%d", VAR_BUTTON_C_PROPERTY,
			 pushbutton_c_count);
		strcat(state, buf_out);
		pushbutton_c_count_prev = pushbutton_c_count;
	}
	if (pushbutton_d_count_prev != pushbutton_d_count) {
		snprintf(buf_out, BUFSIZE, ",\"%s\":%d", VAR_BUTTON_D_PROPERTY,
			 pushbutton_d_count);
		strcat(state, buf_out);
		pushbutton_d_count_prev = pushbutton_d_count;
	}


	/* On receiving led state change notification from cloud, change
	 * the state of the led on the board in callback function and
	 * publish updated state on configured topic.
	 */
	if (led_1_state_prev != led_1_state) {
		snprintf(buf_out, BUFSIZE, ",\"%s\":%d", VAR_LED_1_PROPERTY,
			 led_1_state);
		strcat(state, buf_out);
		led_1_state_prev = led_1_state;
	}

	if (*ptr == ',')
		ptr++;
	if (strlen(state)) {
		snprintf(buf_out, BUFSIZE, "{\"state\": {\"reported\":{%s}}}",
			 ptr);
		wmprintf("Publishing '%s' to AWS\r\n", buf_out);

		/* publish incremented value on pushbutton press on
		 * configured thing */
		ret = aws_iot_shadow_update(&mqtt_client,
					    sp->pMyThingName,
					    buf_out,
					    shadow_update_status_cb,
					    NULL,
					    10, true);
	}
	return ret;
}

/* application thread */
static void aws_starter_demo(os_thread_arg_t data)
{
	int led_state = 0, ret;
	jsonStruct_t led_indicator;
	ShadowParameters_t sp;

	aws_iot_mqtt_init(&mqtt_client);

	ret = aws_starter_load_configuration(&sp);
	if (ret != WM_SUCCESS) {
		wmprintf("aws shadow configuration failed : %d\r\n", ret);
		goto out;
	}

	ret = aws_iot_shadow_init(&mqtt_client);
	if (ret != WM_SUCCESS) {
		wmprintf("aws shadow init failed : %d\r\n", ret);
		goto out;
	}

	ret = aws_iot_shadow_connect(&mqtt_client, &sp);
	if (ret != WM_SUCCESS) {
		wmprintf("aws shadow connect failed : %d\r\n", ret);
		goto out;
	}

	/* indication that device is connected and cloud is started */
	led_on(board_led_2());
	wmprintf("Cloud Started\r\n");

	/* configures property of a thing */
	led_indicator.cb = led_indicator_cb;
	led_indicator.pData = &led_state;
	led_indicator.pKey = "led";
	led_indicator.type = SHADOW_JSON_INT8;

	/* subscribes to delta topic of the configured thing */
	ret = aws_iot_shadow_register_delta(&mqtt_client, &led_indicator);
	if (ret != WM_SUCCESS) {
		wmprintf("Failed to subscribe to shadow delta %d\r\n", ret);
		goto out;
	}

	/* creates a thread which will wait for incoming messages, ensuring the
	 * connection is kept alive with the AWS Service
	 */
	aws_create_shadow_yield_thread();

	while (1) {
		/* Implement application logic here */

		if (device_state == AWS_RECONNECTED) {
			ret = aws_iot_shadow_connect(&mqtt_client, &sp);
			if (ret != WM_SUCCESS) {
				wmprintf("aws shadow reconnect failed: "
					 "%d\r\n", ret);
				goto out;
			} else {
				device_state = AWS_CONNECTED;
				led_on(board_led_2());
			}
		}

		ret = aws_publish_property_state(&sp);
		if (ret != WM_SUCCESS)
			wmprintf("Sending property failed\r\n");

		os_thread_sleep(1000);
	}

	ret = aws_iot_shadow_disconnect(&mqtt_client);
	if (NONE_ERROR != ret) {
		wmprintf("aws iot shadow error %d\r\n", ret);
	}

out:
	os_thread_self_complete(NULL);
	return;
}

void wlan_event_normal_link_lost(void *data)
{
	/* led indication to indicate link loss */
	aws_iot_shadow_disconnect(&mqtt_client);
	device_state = AWS_DISCONNECTED;
}

void wlan_event_normal_connect_failed(void *data)
{
	/* led indication to indicate connect failed */
	aws_iot_shadow_disconnect(&mqtt_client);
	device_state = AWS_DISCONNECTED;
}

/* This function gets invoked when station interface connects to home AP.
 * Network dependent services can be started here.
 */
void wlan_event_normal_connected(void *data)
{
	int ret;
	/* Default time set to 1 October 2015 */
	time_t time = 1443657600;

	wmprintf("Connected successfully to the configured network\r\n");

	if (!device_state) {
		/* set system time */
		wmtime_time_set_posix(time);

		/* create cloud thread */
		ret = os_thread_create(
			/* thread handle */
			&aws_starter_thread,
			/* thread name */
			"awsStarterDemo",
			/* entry function */
			aws_starter_demo,
			/* argument */
			0,
			/* stack */
			&aws_starter_stack,
			/* priority */
			OS_PRIO_3);
		if (ret != WM_SUCCESS) {
			wmprintf("Failed to start cloud_thread: %d\r\n", ret);
			return;
		}
	}

	if (!device_state)
		device_state = AWS_CONNECTED;
	else if (device_state == AWS_DISCONNECTED)
		device_state = AWS_RECONNECTED;
}

int main()
{
	/* initialize the standard input output facility over uart */
	if (wmstdio_init(UART0_ID, 0) != WM_SUCCESS) {
		return -WM_FAIL;
	}

	/* initialize gpio driver */
	if (gpio_drv_init() != WM_SUCCESS) {
		wmprintf("gpio_drv_init failed\r\n");
		return -WM_FAIL;
	}

	wmprintf("Build Time: " __DATE__ " " __TIME__ "\r\n");
	wmprintf("\r\n#### TWITTER VOTER ####\r\n\r\n");

	/* configure pushbutton on device to perform reset to factory */
	configure_reset_to_factory();
	/* configure led and pushbutton to communicate with cloud */
	configure_led_and_button();

	/* This api adds aws iot configuration support in web application.
	 * Configuration details are then stored in persistent memory.
	 */
	enable_aws_config_support();

	/* This api starts micro-AP if device is not configured, else connects
	 * to configured network stored in persistent memory. Function
	 * wlan_event_normal_connected() is invoked on successful connection.
	 */
	wm_wlan_start(MICRO_AP_SSID, MICRO_AP_PASSPHRASE);
	return 0;
}

Board File - Header

C/C++
This is the header for the board file that we need to edit in order to enable more buttons
/*! \file board.h
 * \brief Board Specific APIs
 *
 *  The board specific APIs are provided to help
 *  with porting the SDK onto new boards. These
 *  APIs are board specific and they need to be
 *  modified/implemented according to the actual
 *  board specifications.
 *
 *  Please verify that {board_file}.c file found under wmsdk/src/boards/
 *  reflects the correct hardware configuration for the project.
 */
/*
 *  Copyright 2008-2015, Marvell International Ltd.
 *  All Rights Reserved.
 */

#include <wmtypes.h>
#include <lowlevel_drivers.h>
#include <generic_io.h>

/** Frequency at which CPU should run
 *
 * Mention the frequency at which the CPU should
 * run here. If this frequency is greater than the
 * source clock, internal PLL will be configured.<br>
 *
 * NOTE: Valid frequencies depend upon the source clock.
 * Please refer to the datasheet for further details.
 *
 *  \return Frequency at which CPU should operate.
 */
int board_cpu_freq();

/** 32 KHz crystal
 *
 * If 32 KHz crystal is present on the board and
 * is functional, return true here.
 *
 *  \return true if 32 KHz crystal is present and
 *  functional, false otherwise.
 */
int board_32k_xtal();

/** 32 KHz Oscillator
 *
 * If 32 KHz oscillator is present on the board and
 * is functional, return true here.
 *
 *  \return true if 32 KHz oscillator is present and
 *  functional, false otherwise.
 */
int board_32k_osc();

/** 32 KHz Internal RC Calibration
 *
 * If 32 KHz crystal or oscillator is not present. The
 * internal rc32k can be calibrated using GPT.
 * NOTE1: On MW300 this needs the GPIO24 and GPIO25 to
 * be connected.
 * NOTE2: On MC200 this will work only if 32MHz crystal
 * is present on the board.
 *
 *  \return true if RC32K should be calibrated using GPT
 */
int board_rc32k_calib();

/** Push Button Pressed
 *
 * Depending upon how the push button is
 * connected, corresponding GPIO needs to
 * be checked for either set or reset.
 *
 * If no pushbuttons are implemented on the board,
 * always return FALSE (i.e. button not pressed).
 *
 * \param[in] pin GPIO pin to be used
 * \return TRUE if pressed, FALSE otherwise
 */
int board_button_pressed(int pin);

/** Power On GPIO settings
 *
 * Do board specific power GPIO settings here.
 */
void board_gpio_power_on();

/** UART pin config
 *
 * Select which pins will be used for different UART ports
 *
 * Leave Blank if UART is not implemented on the board.
 *
 * \param[in] id UART port number
 */
void board_uart_pin_config(int id);

/** I2C pin config
 *
 * Select which pins will be used for different I2C ports
 *
 * Leave Blank if I2C is not implemented on the board.
 *
 * \param[in] id I2C port number
 */
void board_i2c_pin_config(int id);

/** SSP pin config
 *
 * Select which pins will be used for different SSP ports
 *
 * Leave Blank if SSP is not implemented on the board.
 *
 * \param[in] id SSP port number
 * \param[in] cs If internal SSPx_FRM (cs=1) should be activated or not.
 */

void board_ssp_pin_config(int id, bool cs);

/** USB pin configuration
 *
 * Select pin configuration for USB.
 *
 */
void board_usb_pin_config();

/** Configuration of GPIO connected to LED 1
 *
 * \note If LED is not present on the board, the gpio member in \ref
 * output_gpio_cfg_t is set to -1 by this API.
 *
 * \return Output GPIO Configuration type \ref output_gpio_cfg_t
 */
output_gpio_cfg_t board_led_1();

/** Configuration of GPIO connected to LED 2
 *
 * \note If LED is not present on the board, the gpio member in \ref
 * output_gpio_cfg_t is set to -1 by this API.
 *
 * \return Output GPIO Configuration type \ref output_gpio_cfg_t
 */
output_gpio_cfg_t board_led_2();

/** Configuration of GPIO connected to LED 3
 *
 * \note If LED is not present on the board, the gpio member in \ref
 * output_gpio_cfg_t is set to -1 by this API.
 *
 * \return Output GPIO Configuration type \ref output_gpio_cfg_t
 */
output_gpio_cfg_t board_led_3();

/** Configuration of GPIO connected to LED 4
 *
 * \note If LED is not present on the board, the gpio member in \ref
 * output_gpio_cfg_t is set to -1 by this API.
 *
 * \return Output GPIO Configuration type \ref output_gpio_cfg_t
 */
output_gpio_cfg_t board_led_4();

/** Pushbutton 1
 *
 * \return GPIO connected to the pushbutton 1 or -WM_FAIL if such pushbutton is
 * not implemented on the board.
 */
int board_button_1();

/** Pushbutton 2
 *
 * \return GPIO connected to the pushbutton 2 or -WM_FAIL if such pushbutton is
 * not implemented on the board.
 */
int board_button_2();

/** Pushbutton 3
 *
 * \return GPIO connected to the pushbutton 3 or -WM_FAIL if such pushbutton is
 * not implemented on the board.
 */
int board_button_3();
/** Pushbutton 4
 *
 * \return GPIO connected to the pushbutton 3 or -WM_FAIL if such pushbutton is
 * not implemented on the board.
 */
int board_button_4();

Board file

C/C++
This is the board file. We have added some code to the standard board file available on github to enable additional push buttons
/*
 *  Copyright (C) 2008-2015, Marvell International Ltd.
 *  All Rights Reserved.
 */

/*
 * This is a board specific configuration file for
 * the RD-88MW302 RD and AB-88MW302 baseboard
 * based on schematic dated 19th June 2014.
 *
 * Details:
 * By default the board file configures the CPU frequncy to 200MHz
 */

#include <wmtypes.h>
#include <wmerrno.h>
#include <wm_os.h>
#include <board.h>
#include <lowlevel_drivers.h>

int board_cpu_freq()
{
	return 200000000;
}

int board_32k_xtal()
{
	return false;
}

int board_32k_osc()
{
	return true;
}

int board_rc32k_calib()
{
	return false;
}

int board_button_pressed(int pin)
{
	if (pin < 0)
		return false;

	GPIO_SetPinDir(pin, GPIO_INPUT);
	if (GPIO_ReadPinLevel(pin) == GPIO_IO_LOW)
		return true;

	return false;
}

void board_gpio_power_on()
{
	/* RF_CTRL pins */
	GPIO_PinMuxFun(GPIO_44, PINMUX_FUNCTION_7);
	GPIO_PinMuxFun(GPIO_45, PINMUX_FUNCTION_7);
}

void board_uart_pin_config(int id)
{
	switch (id) {
	case UART0_ID:
		GPIO_PinMuxFun(GPIO_2, GPIO2_UART0_TXD);
		GPIO_PinMuxFun(GPIO_3, GPIO3_UART0_RXD);
		break;
	case UART1_ID:
	case UART2_ID:
		/* Not implemented yet */
		break;
	}
}

void board_i2c_pin_config(int id)
{
	switch (id) {
	case I2C0_PORT:
		GPIO_PinMuxFun(GPIO_4, GPIO4_I2C0_SDA);
		GPIO_PinMuxFun(GPIO_5, GPIO5_I2C0_SCL);
		break;
	case I2C1_PORT:
		GPIO_PinMuxFun(GPIO_17, GPIO17_I2C1_SCL);
		GPIO_PinMuxFun(GPIO_18, GPIO18_I2C1_SDA);
		break;
	}
}

void board_usb_pin_config()
{
	GPIO_PinMuxFun(GPIO_27, GPIO27_DRVVBUS);
}

void board_ssp_pin_config(int id, bool cs)
{
	/* To do */
	switch (id) {
	case SSP0_ID:
		GPIO_PinMuxFun(GPIO_0, GPIO0_SSP0_CLK);
		if (cs)
			GPIO_PinMuxFun(GPIO_1, GPIO1_SSP0_FRM);
		GPIO_PinMuxFun(GPIO_2, GPIO2_SSP0_TXD);
		GPIO_PinMuxFun(GPIO_3, GPIO3_SSP0_RXD);
		break;
	case SSP1_ID:
		GPIO_PinMuxFun(GPIO_11, GPIO11_SSP1_CLK);
		if (cs)
			GPIO_PinMuxFun(GPIO_12, GPIO12_SSP1_FRM);
		else {
			GPIO_PinMuxFun(GPIO_12, GPIO12_GPIO12);
			GPIO_SetPinDir(GPIO_12, GPIO_INPUT);
		}
		GPIO_PinMuxFun(GPIO_13, GPIO13_SSP1_TXD);
		GPIO_PinMuxFun(GPIO_14, GPIO14_SSP1_RXD);
		break;
	case SSP2_ID:
		break;
	}
}

output_gpio_cfg_t board_led_1()
{
	output_gpio_cfg_t gcfg = {
		.gpio = GPIO_40,
		.type = GPIO_ACTIVE_LOW,
	};

	return gcfg;
}

output_gpio_cfg_t board_led_2()
{
	output_gpio_cfg_t gcfg = {
		.gpio = GPIO_41,
		.type = GPIO_ACTIVE_LOW,
	};

	return gcfg;
}

output_gpio_cfg_t board_led_3()
{
	output_gpio_cfg_t gcfg = {
		.gpio = -1,
	};

	return gcfg;
}

output_gpio_cfg_t board_led_4()
{
	output_gpio_cfg_t gcfg = {
		.gpio = -1,
	};

	return gcfg;
}

int board_button_1()
{
	GPIO_PinMuxFun(GPIO_26, GPIO26_GPIO26);
	return GPIO_26;
}

int board_button_2()
{
	GPIO_PinMuxFun(GPIO_24, GPIO24_GPIO24);
	return GPIO_24;
}

int board_button_3()
{
	GPIO_PinMuxFun(GPIO_22,GPIO22_GPIO22);
	return GPIO_22;
}

int board_button_4()
{
	GPIO_PinMuxFun(GPIO_23,GPIO23_GPIO23);
	return GPIO_23;
}

Tweepy main.py

Python
import tweepy, json
import datetime

def main(event, context):
    consumer_key = ''
    consumer_secret = ''
    access_token = ''
    access_token_secret = ''

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    api = tweepy.API(auth)

    api.update_status("New vote to "+ str(event['state']['reported']) +"!")
    print event
    return 1

if __name__ == '__main__':
    main(1, 2)

Credits

Kedar Sovani

Kedar Sovani

1 project • 3 followers
http://kedar.dumpstack.com

Comments