Hello,

 

I wrote a program to send sensor data over MQTT and select sensor/frequency over mqtt.

 

I added the sensors one by one, but when I added the code for the noise sensor, I get this error:

 

"HardFault_Occured_going to reset the processor "

 

Just by having the NoiseSensor enabled according to the instructions here

 

If I remove the line NoiseSensor_Setup(22050U) in the AppControllerSetup, it works just fine again.

Why is that?

 

edit: I simply added the entire code

 

#include "XdkAppInfo.h"
#undef BCDS_MODULE_ID  /* Module ID define before including Basics package*/
#define BCDS_MODULE_ID XDK_APP_MODULE_ID_APP_CONTROLLER

#include "AppController.h"

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#include "BCDS_CmdProcessor.h"
#include "FreeRTOS.h"
#include "XDK_Utils.h"
#include "task.h"

#include "Serval_Mqtt.h"
#include "BCDS_NetworkConfig.h"
#include "BCDS_WlanConnect.h"

#include "XdkSensorHandle.h"
#include "timers.h"

#include "PAL_initialize_ih.h"
#include "PAL_socketMonitor_ih.h"

#include "BCDS_ServalPal.h"
#include "BCDS_ServalPalWifi.h"
#include "XDK_LED.h"
#include "XDK_Button.h"
#include "XDK_WLAN.h"
#include "Serval_Clock.h"

#include "XDK_NoiseSensor.h"
#include "arm_math.h"

#define MQTT_BROKER_HOST "broker.mqttdashboard.com"
//#define MQTT_BROKER_HOST "192.168.137.1"
#define MQTT_BROKER_PORT 1883
#define TIMER_AUTO_RELOAD_ON pdTRUE
#define TIMERBLOCKTIME UINT32_C(0Xfffff)
#define SECONDS(x) ((portTickType) (x) / portTICK_RATE_MS)
#define ACOUSTIC_BUFFER_SIZE  UINT32_C(32)


#define  XDK_APP_DELAY      UINT32_C(1000)

#define MQTT_BROKER_HOST "broker.mqttdashboard.com"
//#define MQTT_BROKER_HOST "192.168.137.1"
#define MQTT_BROKER_PORT 1883
#define TIMER_AUTO_RELOAD_ON pdTRUE
#define TIMERBLOCKTIME UINT32_C(0Xfffff)
#define SECONDS(x) ((portTickType) (x) / portTICK_RATE_MS)


static void Button1Callback(ButtonEvent_T buttonEvent);
static void Button2Callback(ButtonEvent_T buttonEvent);

Accelerometer_XyzData_T bma280 = {INT32_C(0), INT32_C(0), INT32_C(0)};
Environmental_Data_T bme280 = { INT32_C(0), UINT32_C(0), UINT32_C(0) };
float spl;

float spl;

static Button_Setup_T ButtonSetup =
        {
                .CmdProcessorHandle = NULL,
                .InternalButton1isEnabled = true,
                .InternalButton2isEnabled = true,
                .InternalButton1Callback = Button1Callback,
                .InternalButton2Callback = Button2Callback,
};

static MqttSession_T session;
static MqttSession_T *session_ptr = &session;

static CmdProcessor_T * AppCmdProcessor;
CmdProcessor_T ServalCmdProcessor;

const float SplRatio = pow(10,(-38/20)) * 20e-6;
static arm_rfft_instance_f32 rfft_instance;
static arm_cfft_radix4_instance_f32 cfft_instance;
static float32_t* fftOutputComplex;
static float32_t* fftOutputMag;

const float aku340ConversionRatio = pow(10,(-38/20));

#define SAMPLING_FREQUENCY UINT32_C(100)

#define ACOUSTIC_BUFFER_SIZE  UINT32_C(32)

xTimerHandle measurementTimer;

static xTaskHandle AppControllerHandle = NULL;

uint32_t sRate = 1000;
char deviceName[] = "XDK1";

static WLAN_Setup_T WLANSetupInfo = {
                .IsEnterprise = false,
                .IsHostPgmEnabled = false,
                .SSID = "******",
                .Password = "*******",
                .IsStatic = false,
};

uint32_t initializeFFT(uint32_t windowSize) {
    fftOutputComplex = (float32_t *) malloc(windowSize * sizeof(float32_t) * 2);
    fftOutputMag = (float32_t *) malloc(windowSize * sizeof(float32_t));

  /* Initialize the CFFT/CIFFT module */
    arm_status status = arm_rfft_init_f32(&rfft_instance,
                             &cfft_instance,
                             windowSize,
                             0,  /* forward transform */
                             1); /* normal, not bitreversed, order */
    return status;
}

static uint64_t getCurrentTime(void) {
	uint64_t clock_timestamp;
	Clock_getTimeMillis(&clock_timestamp);
	return clock_timestamp;
}

void publishAccValues(uint32_t type){
	static char *pub_message;
	static char *pub_topic;
	static StringDescr_T pub_topic_descr;
	if(type == 0) {
	}
	else if(type == 1) {
		pub_message = "XDK1";
		float x = (float) bma280.xAxisData;
		float y = (float) bma280.yAxisData;
		float z = (float) bma280.zAxisData;

		uint64_t time = getCurrentTime();

		char str[100];
		float adc_read = (float) time;
		char *tmpSign = (adc_read < 0) ? "-" : "";
		float tmpVal = (adc_read < 0) ? -adc_read : adc_read;

		int tmpInt1 = tmpVal;                  // Get the integer (678).
		float tmpFrac = tmpVal - tmpInt1;      // Get fraction (0.0123).
		int tmpInt2 = trunc(tmpFrac * 10000);  // Turn into integer (123).

		// Print as parts, note that you need 0-padding for fractional bit.

	    sprintf (str, "%s%d.%04d\n", tmpSign, tmpInt1, tmpInt2);

		char xS[10];
		char yS[10];
		char zS[10];

		char semi[2] = {';'};
		snprintf(xS, sizeof xS, "%f", x);
		snprintf(yS, sizeof yS, "%f", y);
		snprintf(zS, sizeof zS, "%f", z);

		pub_topic = "XDK1";
		strcat(xS, semi);
		strcat(xS,yS);
		strcat(xS, semi);
		strcat(xS, zS);
		strcat(xS, semi);
		strcat(xS, str);
		strcat(xS, semi);

		pub_message = xS;
	}
	else {
		return;
	}
	StringDescr_wrap(&pub_topic_descr, pub_topic);
	Mqtt_publish(session_ptr, pub_topic_descr, pub_message
			,strlen(pub_message), MQTT_QOS_AT_MOST_ONE, false);
}

void publishMicValues(uint32_t type) {
	static char *pub_message;
	static char *pub_topic;
	static StringDescr_T pub_topic_descr;

	pub_message = "XDK2";
	uint64_t time = getCurrentTime();

	char str[100];
	float adc_read = (float) time;
	char *tmpSign = (adc_read < 0) ? "-" : "";
	float tmpVal = (adc_read < 0) ? -adc_read : adc_read;

	int tmpInt1 = tmpVal;                  // Get the integer (678).
	float tmpFrac = tmpVal - tmpInt1;      // Get fraction (0.0123).
	int tmpInt2 = trunc(tmpFrac * 10000);  // Turn into integer (123).

	// Print as parts, note that you need 0-padding for fractional bit.

	sprintf (str, "%s%d.%04d\n", tmpSign, tmpInt1, tmpInt2);

	char xS[10];
	char semi[2] = {';'};
	snprintf(xS, sizeof xS, "%f", spl);

	pub_topic = "XDK1";

	strcat(xS, semi);
	strcat(xS, str);
	strcat(xS, semi);

	pub_message = xS;

	StringDescr_wrap(&pub_topic_descr, pub_topic);
	Mqtt_publish(session_ptr, pub_topic_descr, pub_message
			,strlen(pub_message), MQTT_QOS_AT_MOST_ONE, false);
}

void publishEnvValues(uint32_t type){
	static char *pub_message;
	char *pub_topic;
	static StringDescr_T pub_topic_descr;
	if(type == 0) {
	}
	else if(type == 1) {
		pub_message = "XDK2";
		float x = (float) bme280.temperature;
		float y = (float) bme280.humidity;
		float z = (float) bme280.pressure;
		uint64_t time = getCurrentTime();

		char str[100];
		float adc_read = (float) time;
		char *tmpSign = (adc_read < 0) ? "-" : "";
		float tmpVal = (adc_read < 0) ? -adc_read : adc_read;

		int tmpInt1 = tmpVal;                  // Get the integer (678).
		float tmpFrac = tmpVal - tmpInt1;      // Get fraction (0.0123).
		int tmpInt2 = trunc(tmpFrac * 10000);  // Turn into integer (123).

		// Print as parts, note that you need 0-padding for fractional bit.

	    sprintf (str, "%s%d.%04d\n", tmpSign, tmpInt1, tmpInt2);

		char xS[10];
		char yS[10];
		char zS[10];

		char semi[2] = {';'};
		snprintf(xS, sizeof xS, "%f", x);
		snprintf(yS, sizeof yS, "%f", y);
		snprintf(zS, sizeof zS, "%f", z);

		pub_topic = "XDK1";
		strcat(xS, semi);
		strcat(xS,yS);
		strcat(xS, semi);
		strcat(xS, zS);
		strcat(xS, semi);
		strcat(xS, str);
		strcat(xS, semi);

		pub_message = xS;
	}
	else {
		return;
	}
	StringDescr_wrap(&pub_topic_descr, pub_topic);
	Mqtt_publish(session_ptr, pub_topic_descr, pub_message
			,strlen(pub_message), MQTT_QOS_AT_MOST_ONE, false);
}

static void readAccelerometer(void)
{
	Retcode_T returnValue = RETCODE_FAILURE;

    memset(&bma280, 0, sizeof(CalibratedAccel_XyzMps2Data_T));


    returnValue = Accelerometer_readXyzGValue(xdkAccelerometers_BMA280_Handle,&bma280);

         if (RETCODE_OK == returnValue) {
        	 publishAccValues(1);
         }
}

static void readEnvironmental(void)
{
    Retcode_T returnValue = Environmental_readData(xdkEnvironmental_BME280_Handle, &bme280);
    if ( RETCODE_OK == returnValue) {
    	publishEnvValues(1);
    }
}

float calcSoundPressureLevel(float magnitude) {

    float spl;

    if(magnitude == 0){
        spl = 0;
    }

    else {
        spl = (20*log10(magnitude/SplRatio)-20);
    }

    return spl;
}

static void readAcousticSensor(void){
	float acousticData;
    //float sp;

    //double si;
    if (RETCODE_OK == NoiseSensor_ReadRmsValue(&acousticData,10U)) {
        //uint32_t max44009 = UINT32_C(0);
        //Sensor_readLuxData(xdkLightSensor_MAX44009_Handle, &max44009);
        //sp = calcSoundPressure(acousticData);
        spl = calcSoundPressureLevel(acousticData);
        //si = calcSoundIntensityFromSoundPressureLevel(spl);
    }
}

void AccelerationFunction(xTimerHandle pxTimer){
	BCDS_UNUSED(pxTimer);
	readAccelerometer();
}

void EnvironmentFunction(xTimerHandle pxTimer){
	BCDS_UNUSED(pxTimer);
	readEnvironmental();
}

void AcousticFunction(xTimerHandle pxTimer) {
	BCDS_UNUSED(pxTimer);
	readAcousticSensor();
}

static void initAccelerometer(void)
{
    Retcode_T returnValue = RETCODE_FAILURE;
    Retcode_T returnBandwidthValue = RETCODE_FAILURE;
    Retcode_T returnRangeValue = RETCODE_FAILURE;

    /* initialize accelerometer */

    returnValue = Accelerometer_init(xdkAccelerometers_BMA280_Handle);

    if ( RETCODE_OK != returnValue) {
        printf("BMA280 Accelerometer initialization failed\n\r");
    }

    returnBandwidthValue = Accelerometer_setBandwidth(xdkAccelerometers_BMA280_Handle,ACCELEROMETER_BMA280_BANDWIDTH_125HZ);

    if (RETCODE_OK != returnBandwidthValue) {
        printf("Configuring bandwidth failed \n\r");
    }
    returnRangeValue = Accelerometer_setRange(xdkAccelerometers_BMA280_Handle,ACCELEROMETER_BMA280_RANGE_2G);

    if (RETCODE_OK != returnRangeValue) {
        printf("Configuring range failed \n\r");
    }
}

static void initEnvironmental(void)
{
    Retcode_T returnValue = RETCODE_FAILURE;
    Retcode_T returnOverSamplingValue = RETCODE_FAILURE;
    Retcode_T returnFilterValue = RETCODE_FAILURE;

    /* initialize environmental sensor */

    returnValue = Environmental_init(xdkEnvironmental_BME280_Handle);
    if ( RETCODE_OK != returnValue) {
        printf("BME280 Environmental Sensor initialization failed\n\r");
    }

    returnOverSamplingValue = Environmental_setOverSamplingPressure(xdkEnvironmental_BME280_Handle,ENVIRONMENTAL_BME280_OVERSAMP_2X);
    if (RETCODE_OK != returnOverSamplingValue) {
        printf("Configuring pressure oversampling failed \n\r");
    }

    returnFilterValue = Environmental_setFilterCoefficient(xdkEnvironmental_BME280_Handle,ENVIRONMENTAL_BME280_FILTER_COEFF_2);
    if (RETCODE_OK != returnFilterValue) {
        printf("Configuring pressure filter coefficient failed \n\r");
    }
}

void servalPalSetup(void) {
	CmdProcessor_Initialize(&ServalCmdProcessor, "ServalCmdPrc", 3,1000,10);
	ServalPal_Initialize(&ServalCmdProcessor);
	ServalPalWiFi_Init();
	ServalPalWiFi_StateChangeInfo_T stateChangeInfo = {
			SERVALPALWIFI_OPEN, INT16_C(0) };
	ServalPalWiFi_NotifyWiFiEvent(SERVALPALWIFI_STATE_CHANGE, &stateChangeInfo);
}

static void publish(void){

	static char *pub_message = "XDK1 Connected;";
	static char *pub_topic = "Connect";
	static StringDescr_T pub_topic_descr;
	/*StringDescr_wrap(&pub_topic_descr, pub_topic);
	Mqtt_publish(session_ptr, pub_topic_descr, pub_message
			,strlen(pub_message), MQTT_QOS_AT_MOST_ONE, false);*/

	uint64_t time = getCurrentTime();
	printf("published\n\r");
	char str[100];
	float adc_read = (float) time;
	char *tmpSign = (adc_read < 0) ? "-" : "";
	float tmpVal = (adc_read < 0) ? -adc_read : adc_read;

	int tmpInt1 = tmpVal;                  // Get the integer (678).
	float tmpFrac = tmpVal - tmpInt1;      // Get fraction (0.0123).
	int tmpInt2 = trunc(tmpFrac * 10000);  // Turn into integer (123).

	// Print as parts, note that you need 0-padding for fractional bit.

	sprintf (str, "%s%d.%04d\n", tmpSign, tmpInt1, tmpInt2);

	char *xS = "XDK1:";
	strcat(xS, str);
	StringDescr_wrap(&pub_topic_descr, pub_topic);
	Mqtt_publish(session_ptr, pub_topic_descr, pub_message
			,strlen(pub_message), MQTT_QOS_AT_MOST_ONE, false);
}

static void Button1Callback(ButtonEvent_T buttonEvent)
{
    Retcode_T retcode = RETCODE_OK;
    switch (buttonEvent)
    {
    case BUTTON_EVENT_PRESSED:{
        if (RETCODE_OK == retcode)
        {
        	//publish();
        	LED_On(LED_INBUILT_ORANGE);
        	printf("Button1Callback : PB1 Pressed \r\n");
        	xTimerStart(measurementTimer, TIMERBLOCKTIME);
        }
        else
        {
            printf("Button1Callback : PB1 Pressed but setting LED state failed \r\n");
        }
    }
        break;

    case BUTTON_EVENT_RELEASED: {
        if (RETCODE_OK == retcode)
        {
            printf("Button1Callback : PB1 Released \r\n");
        }
        else
        {
            printf("Button1Callback : PB1 Released but setting LED state failed \r\n");
        }
    }
        break;

    default:
        printf("Button1Callback : Unsolicited button event occurred for PB1 \r\n");
        retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_INVALID_PARAM);
        break;
    }
    if (RETCODE_OK != retcode)
    {
        Retcode_RaiseError(retcode);
    }
}

static void Button2Callback(ButtonEvent_T buttonEvent)
{
    Retcode_T retcode = RETCODE_OK;
    switch (buttonEvent)    {
    case BUTTON_EVENT_PRESSED: {
        LED_Off(LED_INBUILT_ORANGE);
        if (RETCODE_OK == retcode){
            printf("Button2Callback : PB2 pressed \r\n");
            xTimerStop(measurementTimer, TIMERBLOCKTIME);
        }
        else        {
            printf("Button2Callback : PB2 Pressed but setting LED state failed \r\n");
        }
    }
        break;

    case BUTTON_EVENT_RELEASED:        {
        retcode = LED_Off(LED_INBUILT_RED);
        if (RETCODE_OK == retcode)        {
            retcode = LED_Off(LED_INBUILT_ORANGE);
        }
        if (RETCODE_OK == retcode)        {
            retcode = LED_On(LED_INBUILT_YELLOW);
        }
        if (RETCODE_OK == retcode)        {
            printf("Button2Callback : PB2 Released\n\r");
        }
        else {
            printf("Button2Callback : PB2 Released but setting LED state failed \r\n");
        }
    }
        break;

    default:
        printf("Button2Callback : Unsolicited button event occurred for PB2 \r\n");
        retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_INVALID_PARAM);
        break;
    }
    if (RETCODE_OK != retcode)    {
        Retcode_RaiseError(retcode);
    }
}

retcode_t init(void){
	retcode_t rc_initialize = Mqtt_initialize();
	if(rc_initialize == RC_OK) {
		session_ptr = &session;
		Mqtt_initializeInternalSession(session_ptr);
	}
	return rc_initialize;
}

static void handle_connection(MqttConnectionEstablishedEvent_T connectionData){
	int rc_connect = (int) connectionData.connectReturnCode;
	printf("Connection Event:\n\r"
			"\tServer Return Code: %d (0 for success)\n\r",
			(int) rc_connect);
}

static void handle_incoming_publish(MqttPublishData_T publishData){
	int topic_length = publishData.topic.length + 1;
	int data_length = publishData.length + 1;
	char published_topic_buffer[topic_length];
	char published_data_buffer[data_length];
	snprintf(published_topic_buffer, topic_length, publishData.topic.start);
	snprintf(published_data_buffer, data_length,
			(char *) publishData.payload);
	printf("Kommt an \n\r");
	printf("antwort: %s \n\r", published_data_buffer);

	char delim[] = "\\";

	char *ptr = strtok(published_data_buffer, delim);
	char *dName;
	char *command;
	char *type;
	char *property;
	char *value;
	uint32_t counter = 0;

	while(ptr != NULL){
		printf("'%s' \n\r",ptr);
		if(counter == 0) {
			dName = ptr;
		}
		else if(counter == 1) {
			command = ptr;
		}
		else if(counter == 2) {
			type = ptr;
		}
		else if(counter == 3) {
			property = ptr;
		}
		else if(counter == 4) {
			value = ptr;
		}
		ptr = strtok(NULL, delim);
		counter++;
	}
	if(strcmp(dName, deviceName) != 0) {
		return;
	}
	if(strcmp(command, "Set") == 0) {
		if(strcmp(property, "Frequency") == 0) {
			xTimerStop(measurementTimer, TIMERBLOCKTIME);
			sRate = atoi(value);
			printf("sRate: %d\n\r", sRate);
			measurementTimer = xTimerCreate((char* const) "Application to measure with 1Hz",
					SECONDS(sRate),
					TIMER_AUTO_RELOAD_ON,
					NULL,
					AccelerationFunction);
			//xTimerStart(measurementTimer, TIMERBLOCKTIME);
		}
	}
	else if(strcmp(command, "Start") == 0) {
		printf("Timer soll starten 2\n\r");
		printf("sRate: %d\n\r", sRate);
		xTimerStop(measurementTimer, TIMERBLOCKTIME);
		measurementTimer = xTimerCreate((char* const) "Application to measure with 1Hz",
				SECONDS(sRate),
				TIMER_AUTO_RELOAD_ON,
				NULL,
				AccelerationFunction);
		xTimerStart(measurementTimer, TIMERBLOCKTIME);
		printf("Timer soll starten 3\n\r");
	}
	else if(strcmp(command, "Stop") == 0) {
		xTimerStop(measurementTimer, TIMERBLOCKTIME);
	}
	else if(strcmp(command, "Change") == 0) {
		sRate = atoi(value);
		printf("sRate %d \n\r",sRate);
		if(strcmp(property, "Acceleration") == 0) {
			xTimerStop(measurementTimer, TIMERBLOCKTIME);
			measurementTimer = xTimerCreate((char* const) "Application to measure with 1Hz",
					SECONDS(sRate),
					TIMER_AUTO_RELOAD_ON,
					NULL,
					AccelerationFunction);
			xTimerStart(measurementTimer, TIMERBLOCKTIME);
		}
		else if(strcmp(property, "Environment") == 0) {
			xTimerStop(measurementTimer, TIMERBLOCKTIME);
			measurementTimer = xTimerCreate((char* const) "Application to measure with 1Hz",
					SECONDS(sRate),
					TIMER_AUTO_RELOAD_ON,
					NULL,
					EnvironmentFunction);
			xTimerStart(measurementTimer, TIMERBLOCKTIME);
		}
		else if(strcmp(property, "Microphone") == 0){
			printf("Vor stop\n\r");
			xTimerStop(measurementTimer, TIMERBLOCKTIME);
			measurementTimer = xTimerCreate((char* const) "Application to measure with 1Hz",
					SECONDS(sRate),
					TIMER_AUTO_RELOAD_ON,
					NULL,
					AcousticFunction);
			printf("nach set \n\r");
			xTimerStart(measurementTimer, TIMERBLOCKTIME);
			printf("nach start \n\r");
		}
	}
}

void config_set_connect_data(void){
	static char *device_name = "XDK1";
	session_ptr->MQTTVersion = 3;
	session_ptr->keepAliveInterval = 100;
	session_ptr->cleanSession = true;
	session_ptr->will.haveWill = false;
	StringDescr_T device_name_descr;
	StringDescr_wrap(&device_name_descr, device_name);
	session_ptr->clientID=device_name_descr;
}

void config_set_target(void){
	static char mqtt_broker[64];
		const char *mqtt_broker_format = "mqtt://%s:%d";

		char server_ip_buffer[13];


		Ip_Address_T ip;
		PAL_getIpaddress((uint8_t *) MQTT_BROKER_HOST, &ip);


		char test[15] = {'1','9','2','.','1','6','8','.','1','2','8','.','0','0','1'};

		printf("1\n\r");
		printf(test);
		printf("\n\r1\n\r");

		//Ip_convertAddrToString(&ip, test);
		sprintf(mqtt_broker, mqtt_broker_format,
				test, MQTT_BROKER_PORT);
		SupportedUrl_fromString(mqtt_broker,
				(uint16_t) strlen(mqtt_broker), &session_ptr->target);
}

static void subscribe(void){
	static char*sub_topic = "XDK1";
	static StringDescr_T subscription_topics[2];
	static Mqtt_qos_t qos[1];
	StringDescr_wrap(&(subscription_topics[0]), sub_topic);
	qos[0] =MQTT_QOS_AT_MOST_ONE;
	Mqtt_subscribe(session_ptr, 1, subscription_topics, qos);
}

retcode_t not_connect(void){
	retcode_t rc =RC_INVALID_STATUS;
	rc = Mqtt_connect(session_ptr);
	if (rc != RETCODE_OK) {
		printf("Could not connect, error 0x%04x\n", rc);
	}
	return rc;
}

retcode_t event_handler(MqttSession_T* session, MqttEvent_t event,
		const MqttEventData_t* eventData) {
	BCDS_UNUSED(session);
	switch(event){
		case MQTT_CONNECTION_ESTABLISHED:
			handle_connection(eventData->connect);
			// subscribing and publishing can now be done
			subscribe();
			publish();
			printf("hier kommt publish2\n\r");
			break;
		case MQTT_CONNECTION_ERROR:
			handle_connection(eventData->connect);
			break;
		case MQTT_INCOMING_PUBLISH:
			handle_incoming_publish(eventData->publish);
			break;
		case MQTT_SUBSCRIPTION_ACKNOWLEDGED:
			//printf("Subscription Successful\n\r");
			break;
		case MQTT_PUBLISHED_DATA:
			//printf("Publish Successful\n\r");
			break;
		case MQTT_PUBLISH_SEND_FAILED:
		//	printf("Publish failed\n\r");
			break;
		case MQTT_PUBLISH_TIMEOUT:
			printf("Publish timeout\n\r");
			break;
		default:
			printf("Unhandled MQTT Event: %d\n\r", event);
			LED_On(LED_INBUILT_YELLOW);
			LED_On(LED_INBUILT_RED);
			LED_On(LED_INBUILT_ORANGE);
			break;
	}
	return RC_OK;
}

void config_set_event_handler(void){
	session_ptr->onMqttEvent = event_handler;
}

static void AppControllerFire(void* pvParameters){
    BCDS_UNUSED(pvParameters);

    while (1)
    {
        vTaskDelay(XDK_APP_DELAY);
    }
}

static void AppControllerEnable(void * param1, uint32_t param2){
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);
    Retcode_T retcode = RETCODE_OK;

    retcode = WLAN_Enable();
    if(retcode == RETCODE_OK) {
    	LED_On(LED_INBUILT_YELLOW);
    }
    retcode = init();
    if(retcode == RC_OK){
    	config_set_target();
    	config_set_connect_data();
        config_set_event_handler();
        not_connect();
        LED_On(LED_INBUILT_RED);
    }
    else {
    	printf("Initialize Failed\n\r");
    }
    retcode = LED_Enable();
    if (RETCODE_OK == retcode){
    	retcode  = Button_Enable();
    }
    RETCODE_OK == NoiseSensor_Enable();
    if (RETCODE_OK == retcode)
    {
        if (pdPASS != xTaskCreate(AppControllerFire, (const char * const ) "AppController", TASK_STACK_SIZE_APP_CONTROLLER, NULL, TASK_PRIO_APP_CONTROLLER, &AppControllerHandle))
        {
            retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_OUT_OF_RESOURCES);
        }
    }
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerEnable : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0);
    }
    Utils_PrintResetCause();
}

static void AppControllerSetup(void * param1, uint32_t param2){
    BCDS_UNUSED(param1);
    BCDS_UNUSED(param2);
    Retcode_T retcode = RETCODE_OK;

    WLAN_Setup(&WLANSetupInfo);
    PAL_initialize();
    PAL_socketMonitorInit();

    initAccelerometer();
    initEnvironmental();
    initializeFFT(ACOUSTIC_BUFFER_SIZE);

    retcode = LED_Setup();
    if (RETCODE_OK == retcode){
    	ButtonSetup.CmdProcessorHandle = AppCmdProcessor;
    	retcode = Button_Setup(&ButtonSetup);
    }
    retcode = NoiseSensor_Setup(22050U);

    retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerEnable, NULL, UINT32_C(0));
    if (RETCODE_OK != retcode)
    {
        printf("AppControllerSetup : Failed \r\n");
        Retcode_RaiseError(retcode);
        assert(0);
    }
}


void AppController_Init(void * cmdProcessorHandle, uint32_t param2)
{
    BCDS_UNUSED(param2);

    Retcode_T retcode = RETCODE_OK;

    if (cmdProcessorHandle == NULL)
    {
        printf("AppController_Init : Command processor handle is NULL \r\n");
        retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_NULL_POINTER);
    }
    else
    {
        AppCmdProcessor = (CmdProcessor_T *) cmdProcessorHandle;
        retcode = CmdProcessor_Enqueue(AppCmdProcessor, AppControllerSetup, NULL, UINT32_C(0));
    }

    if (RETCODE_OK != retcode)
    {
        Retcode_RaiseError(retcode);
        assert(0);
    }
    measurementTimer = xTimerCreate((char* const) "Application to measure with 1Hz",
	   			SECONDS(1000),
				TIMER_AUTO_RELOAD_ON,
				NULL,
				EnvironmentFunction);
}

[Zum Verschieben anwählen und ziehen]

 

0 (0 票)
RE: HardFault_Occured_going to reset the processor - Noise Sensor
答复
19-10-9 上午7:10 回复Markus B.。

Hi Markus,

- It is recommended to uses latest workbench version 3.6.0. In this version Noise sensor will work with other sensors. But not the case for previous workbench version.

- Also please refer StreamSensorDataOverUsb example application. Here noise sensor is used along with other sensors.

Thank You :)

0 (0 票)