Hi Alex,
Since I am using Texas Instruments board, I referred to note c library for TI MSP430.
I notice the example_min.c JSON messages has a newline(\n) at the end. So, I modified my test program to include this and it worked.
I am using simplelink_cc13x2_26x2_sdk_5_10_00_48 and modified pininterrupt example program. Here is code.
* ======== pinInterrupt.c ========
*/
#include <unistd.h>
#include <string.h>
/* Driver Header files */
#include <ti/drivers/PIN.h>
#include <ti/drivers/UART.h>
/* POSIX Header files */
#include <semaphore.h>
/* TI-Drivers Configuration */
#include "ti_drivers_config.h"
/*
* Device specific header file containing CPUdelay()
*/
#include <ti/devices/DeviceFamily.h>
#include DeviceFamily_constructPath(driverlib/cpu.h)
static sem_t sem;
/* Pin driver handles */
static PIN_Handle buttonPinHandle;
static PIN_Handle ledPinHandle;
/* Global memory storage for a PIN_Config table */
static PIN_State buttonPinState;
static PIN_State ledPinState;
/*
* Initial LED pin configuration table
* - LEDs CONFIG_PIN_LED_0 is on.
* - LEDs CONFIG_PIN_LED_1 is off.
*/
PIN_Config ledPinTable[] = {
CONFIG_PIN_LED_0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
CONFIG_PIN_LED_1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
/*
* Application button pin configuration table:
* - Buttons interrupts are configured to trigger on falling edge.
*/
PIN_Config buttonPinTable[] = {
CONFIG_PIN_BUTTON_0 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
CONFIG_PIN_BUTTON_1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_NEGEDGE,
PIN_TERMINATE
};
// The request field sets up service operation parameters
#define PRODUCT_UID "your product uid"
#define F_PRODUCT "\"product\":\"" PRODUCT_UID "\","
#define F_REQ "\"req\":\"hub.set\""
#define F_MODE "\"mode\":\"continuous\""
const char syncnotehub[100] = "{\"req\":\"hub.sync\"}\n";
UART_Handle uart;
UART_Params uartParams;
uint8_t flag = 0;
int32_t semStatus;
/*
* ======== buttonCallbackFxn ========
* Push buttons callback function.s
*/
void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId) {
uint32_t currVal = 0;
/* Debounce logic, only toggle if the button is still pushed (low) */
CPUdelay(8000 * 50);
if (!PIN_getInputValue(pinId)) {
/* Toggle LED based on the button pressed */
switch (pinId) {
case CONFIG_PIN_BUTTON_0:
currVal = PIN_getOutputValue(CONFIG_PIN_LED_0);
PIN_setOutputValue(ledPinHandle, CONFIG_PIN_LED_0, !currVal);
flag = 1;
break;
case CONFIG_PIN_BUTTON_1:
currVal = PIN_getOutputValue(CONFIG_PIN_LED_1);
PIN_setOutputValue(ledPinHandle, CONFIG_PIN_LED_1, !currVal);
flag = 2;
default:
/* Do nothing */
break;
}
sem_post(&sem);
}
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
/* Create semaphore */
semStatus = sem_init(&sem, 0, 0);
if (semStatus != 0) {
/* Error creating semaphore */
while (1);
}
/* Open LED pins */
ledPinHandle = PIN_open(&ledPinState, ledPinTable);
if(!ledPinHandle) {
/* Error initializing LED pins */
while(1);
}
buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
if(!buttonPinHandle) {
/* Error initializing button pins */
while(1);
}
/* Setup callback for button pins */
if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
/* Error registering button callback function */
while(1);
}
UART_init();
/* Configure the LED pin */
//GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.baudRate = 9600;
uart = UART_open(CONFIG_UART_0, &uartParams);
if (uart == NULL) {
/* UART_open() failed */
while (1);
}
char *request1 = "{" "\"req\":\"hub.set\"" "," "\"product\":\"" PRODUCT_UID "\"," "\"mode\":\"continuous\"" "}\n";
uint8_t len = 0;
len = strlen(request1);
UART_write(uart, request1, len);
//UART_write(uart, initnote, sizeof(initnote));
char *request2 = "{\"req\":\"note.add\",\"sync\":true,\"file\":\"sensors.qo\",\"body\":{\"count\":\"20\"}}\n";
while(1)
{
/* Do not write until read callback executes */
sem_wait(&sem);
if(flag == 1)
{
flag = 0;
len = strlen(request2);
UART_write(uart, request2, len);
}
else if (flag == 2)
{
flag = 0;
len = strlen(syncnotehub);
UART_write(uart, syncnotehub, len);
}
}
}
Here is output at Notehub.
This issue has been solved. I am moving forward with my project.
Regards,
Markel
type or paste code here