Search code examples
ciotcontikicontiki-process

Start Contiki process from a process


I am using contikiOS and C, I am trying to create code that will wait for 10s then print the temperature. It will then start a different process and record temp every 1s. It will check when temperature exceeds 28c and turn led on.

Currently, it executes as follows:

Waits 10s, Prints temp, Waits 10s, Terminates

Here is my code:

#include "dev/light-sensor.h"
#include "dev/sht11-sensor.h"
#include "dev/leds.h"
#include <stdio.h> /* For printf() */


unsigned short d1(float f) // Integer part
{
  return((unsigned short)f);
}
unsigned short d2(float f) // Fractional part
{
  return(1000*(f-d1(f)));
}


/*---------------------------------------------------------------------------*/
PROCESS(alarm, "alarm");

/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
PROCESS(detect, "detect");
AUTOSTART_PROCESSES(&detect);
/*---------------------------------------------------------------------------*/




PROCESS_THREAD(detect, ev, data)
{

    static struct etimer timer;
    PROCESS_BEGIN();
    etimer_set(&timer, CLOCK_CONF_SECOND * 10);
    SENSORS_ACTIVATE(sht11_sensor);
    leds_off(LEDS_ALL);

    while (1) {
        if (!etimer_pending()) {
            break;
        }
        else {


            PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);

            float temp = 0.01*sht11_sensor.value(SHT11_SENSOR_TEMP) - 39.6;
            printf("\n%u.%03u C", d1(temp), d2(temp));

            if (temp > 28) {

                leds_on(LEDS_ALL);
                clock_wait(CLOCK_SECOND);


                leds_off(LEDS_ALL);

            }
            if (temp <= 28) {

                leds_off(LEDS_ALL);
            }


        }
        etimer_stop(&timer);

    }
    PROCESS_EXIT();
    PROCESS_START(&alarm, NULL);
    PROCESS_END();
}


/*---------------------------------------------------------------------------*/


PROCESS_THREAD(alarm, ev, data)
{

    static struct etimer timer1;
    PROCESS_BEGIN();
    etimer_set(&timer1, CLOCK_SECOND);
    SENSORS_ACTIVATE(sht11_sensor);
    leds_off(LEDS_ALL);
    while (1) {
        PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
        float temp = 0.01*sht11_sensor.value(SHT11_SENSOR_TEMP) - 39.6;
        printf("\n%u.%03u C", d1(temp), d2(temp));

        if (temp > 28) {

            leds_on(LEDS_ALL);
            clock_wait(CLOCK_SECOND);


            leds_off(LEDS_ALL);

        }
        if (temp <= 28) {

            leds_off(LEDS_ALL);
        }
        etimer_reset(&timer1);






    }

    PROCESS_END();
}






Solution

  • According to the contiki wiki on processes, the process_start() method is lowercase. Change that and your program should work.