Thingy:91 resets only when USB is connected

Hello everyone,

there seems to be an issue with my programm I am unable to solve. When I flash/reset the thingy via VSCode with Segger J-Link mini EDU and USB it boots just fine and the application runs even if I disconnect it after. But if I try to reset it just with the J-link without the USB or simply by a power-on reset it doesn't do anything. 

The battery is fine and when f.e. the blinky demo is flashed it works without issues. What am I missing?

Thanks for your help.

The app is supposed to first connect to the network, then measure the airquality and send a message via MQTT. After that go to sleep for 5 mins and repeat.

This is my main():

void main(void)
{
	k_msleep(500); //tested if delaying helps
	gpio_pin_configure_dt(&red_led, GPIO_OUTPUT_ACTIVE);
	/*Initialisierung und Aufbau der Internetverbindung*/
	int err;
	printk("Connecting to LTE network. This may take a few minutes...\n");
	k_msleep(500); //tested if delaying helps
	err = lte_lc_init_and_connect_async(lte_handler);
	if (err) {
			printk("lte_lc_init_and_connect_async, error: %d\n", err);
			return;
	}
	err = lte_lc_psm_req(true); //enabling PSM
	if (err) {
			printk("lte_lc_psm_req, error: %d\n", err);
			return;
	}
	k_sem_take(&lte_connected, K_FOREVER);
	gpio_pin_configure_dt(&red_led, GPIO_OUTPUT_INACTIVE);

	/*Abarbeitung des weiterführenden Programms*/
	printMessageConnection();
	connectedLED();
	sensINIT();	

	err = client_init(&client);
	if (err) {
		printk("Failed to initialize MQTT client: %d\n", err);
		return;
	}

do_connect:
	err = mqtt_connect(&client);
	if (err) {
		printk("Error in mqtt_connect: %d\n", err);
		goto do_connect;
	}
	err = fds_init(&client,&fds);
	if (err) {
		printk("Error in fds_init: %d\n", err);
		return;
	}


	while(1){

		err = poll(&fds, 1, mqtt_keepalive_time_left(&client));
		if (err < 0) {
			printk("Error in poll(): %d\n", errno);
			break;
		}

		err = mqtt_live(&client);
		if ((err != 0) && (err != -EAGAIN)) {
			printk("Error in mqtt_live: %d\n", err);
			break;
		}

		if ((fds.revents & POLLIN) == POLLIN) {
			err = mqtt_input(&client);
			if (err != 0) {
				printk("Error in mqtt_input: %d\n", err);
				break;
			}
		}

		if ((fds.revents & POLLERR) == POLLERR) {
			printk("POLLERR\n");
			break;
		}

		if ((fds.revents & POLLNVAL) == POLLNVAL) {
			printk("POLLNVAL\n");
			break;
		}

		airQualLED();
		sensValues();
		sendMsg();
		k_sleep(K_MINUTES(MAIN_SLEEP));
	}

	printk("Disconnecting MQTT client\n");

	err = mqtt_disconnect(&client);
	if (err) {
		printk("Could not disconnect MQTT client: %d\n", err);
	}
	goto do_connect;
}

Parents
  • Hello,

    Sorry I couldn't find a real reason for this issue. But can you once cross check your configuration file with the sample configuration(uner:C:\ncs\v2.4.0\nrf\samples\net\mqtt) I pointed out in my last response. I also recommend you to go through this tutorial and see if you have missed or added anything. You can also share your prj.conf file to have better insight into this.

    Kind Regards,

    Abhijith

  • Hey,

    No worries. :) I probably just missed something small. Since the code works once the thingy is resetted and it's just a project for college, I am not toooo worried if the resetting doesn't work. 

    Here's my prj.conf:

    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    CONFIG_LTE_NETWORK_MODE_NBIOT=y
    ## Power saving timers.
    CONFIG_LTE_PSM_REQ_RPTAU="00000011"
    ### 20 seconds active time.
    CONFIG_LTE_PSM_REQ_RAT="10000010"
    ## Enable notifications when modem enters PSM
    CONFIG_LTE_LC_MODEM_SLEEP_NOTIFICATIONS=y
    
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    
    CONFIG_SENSOR=y
    
    CONFIG_AT_HOST_LIBRARY=y
    
    # Memory
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # Modem library
    CONFIG_NRF_MODEM_LIB=y
    
    CONFIG_MQTT_LIB=y
    CONFIG_MQTT_CLEAN_SESSION=y
    
    CONFIG_MQTT_PUB_TOPIC="fhswf/publish/thingy"
    CONFIG_MQTT_SUB_TOPIC="fhswf/subscribe/thingy"
    CONFIG_MQTT_BROKER_HOSTNAME="test.mosquitto.org"
    CONFIG_MQTT_BROKER_PORT=1883

Reply
  • Hey,

    No worries. :) I probably just missed something small. Since the code works once the thingy is resetted and it's just a project for college, I am not toooo worried if the resetting doesn't work. 

    Here's my prj.conf:

    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    CONFIG_LTE_NETWORK_MODE_NBIOT=y
    ## Power saving timers.
    CONFIG_LTE_PSM_REQ_RPTAU="00000011"
    ### 20 seconds active time.
    CONFIG_LTE_PSM_REQ_RAT="10000010"
    ## Enable notifications when modem enters PSM
    CONFIG_LTE_LC_MODEM_SLEEP_NOTIFICATIONS=y
    
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    
    CONFIG_SENSOR=y
    
    CONFIG_AT_HOST_LIBRARY=y
    
    # Memory
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # Modem library
    CONFIG_NRF_MODEM_LIB=y
    
    CONFIG_MQTT_LIB=y
    CONFIG_MQTT_CLEAN_SESSION=y
    
    CONFIG_MQTT_PUB_TOPIC="fhswf/publish/thingy"
    CONFIG_MQTT_SUB_TOPIC="fhswf/subscribe/thingy"
    CONFIG_MQTT_BROKER_HOSTNAME="test.mosquitto.org"
    CONFIG_MQTT_BROKER_PORT=1883

Children
No Data
Related