Exemplo n.º 1
0
/*---------------------------------------------------------------*/
static void sample_fun(void)
{
	ctimer_reset(&ct);
	ctimer_restart(&reset_timer);

	MPU_status = mpu_sample_all(&sample_data);



	if (MPU_status != 0)
	{

		PRINTF("%d,%d,%d,%d,%d,%d,%d\n",sample_data.data.accel_x,sample_data.data.accel_y,sample_data.data.accel_z,sample_data.data.tp,sample_data.data.gyro_x,sample_data.data.gyro_y,sample_data.data.gyro_z);

		// sending acceleration data
		mpu_get_acc(&sample_data,&data_sample);
		app_conn_send((uint8_t*)&data_sample,MPU_DATA_ACC_GYRO_SIZE);


		// sending gyro data
		mpu_get_gyro(&sample_data,&data_sample);
		app_conn_send((uint8_t*)&data_sample,MPU_DATA_ACC_GYRO_SIZE);


		// sending temperature data
		//mpu_get_tp(&sample_data,&tp_data_sample);
		//app_conn_send((uint8_t*)&tp_data_sample,MPU_DATA_TP_SIZE);


	}
	else
	{
		printf("Cannot sample data\n");
	}
}
Exemplo n.º 2
0
static void reset_sample_timer(void)
{
	//ctimer_set(&ct,SAMPLE_RATE,sample_fun,(void*)NULL);
	ctimer_reset(&ct);
	ctimer_restart(&reset_timer);
	has_reset = has_reset + 1;
	printf("reset sample fun ctimer %u\n",has_reset);
}
Exemplo n.º 3
0
void global_presence_detected(void) {
#if PRESENCE_DETECTOR_SERVER
    if(global_presence != PRESENCE) {
        global_presence = PRESENCE;
        broadcast_value(EP_PRESENCE_DETECTOR);
    }
    ctimer_restart(&pd_timeout);
#endif
}
Exemplo n.º 4
0
/* Call back for led toggle timer to toggle leds */
static void
ct_callback(void *ptr)
{
  static uint8 toggle_status = 0;
  if(toggle_status) {
    leds_set(LEDS_RED);
  } else {
    leds_set(LEDS_GREEN);
  } ctimer_restart(&ct);
  toggle_status ^= 0x01;
}
Exemplo n.º 5
0
static void send_packet(struct mqtt_sn_connection *mqc, char* data, size_t len)
{
  simple_udp_send(&(mqc->sock), data, len);//these datatypes should all cast fine
  if (mqc->keep_alive>0 && mqc->stat == MQTTSN_CONNECTED)
  {
    //normally we would use this to make sure that we are always sending data to keep the connection alive
    //but since the gateway does not support pubacks, we will always be relying on a
    //steady stream of pings to ensure that the connection stays alive.
    ctimer_restart(&(mqc->send_timer));
  }
}
Exemplo n.º 6
0
void raw_presence_detected(void) {
#if PRESENCE_DETECTOR_CLIENT
    uint8_t tmp = global_presence;
    presence = PRESENCE_DETECTOR_CLIENT_GROUP;
    global_presence = presence;
    broadcast_value(EP_PRESENCE_DETECTOR);
    global_presence = tmp;
    if(PRESENCE_DETECTOR_CLIENT_KEEP_ALIVE != 0) {
        ctimer_restart(&pd_keep_alive);
    }
#endif
}
Exemplo n.º 7
0
void response_handler(ChannelState *state, DataPayload *dp){
	if (state->state != STATE_CONNECTED && state->state != STATE_PING){
		PRINTF("Not connected to device!\n");
		return;
	}
	state->ticks = 100;
	ResponseMsg *rmsg = (ResponseMsg *)dp->data;
	PRINTF("%s %d\n", rmsg->name, uip_ntohs(rmsg->data));
	/*RESET PING TIMER*/
	ctimer_restart(&(state->timer));
	process_post_synch(state->ccb.client_process, KNOT_EVENT_DATA_READY, rmsg);
}
Exemplo n.º 8
0
/**
 * Handles TCP events from Simple TCP
 */
static void
tcp_event(struct tcp_socket *s, void *ptr, tcp_socket_event_t event)
{
  struct mqtt_connection* conn = ptr;

  /* Take care of event */
  switch(event) {

    /* Fall through to manage different disconnect event the same way. */
    case TCP_SOCKET_CLOSED:
    case TCP_SOCKET_TIMEDOUT:
    case TCP_SOCKET_ABORTED: {

      ctimer_stop(&conn->keep_alive_timer);
      call_event(conn, MQTT_EVENT_DISCONNECTED, &event);

      /* If connecting retry */
      if(conn->state == MQTT_CONN_STATE_TCP_CONNECTING ||
         conn->auto_reconnect == 1) {
        DBG("MQTT - Disconnected by tcp event %d, reconnecting...",
            event);
        connect_tcp(conn);
      }
      else {
        conn->state = MQTT_CONN_STATE_NOT_CONNECTED;
      }
      break;
    }
    case TCP_SOCKET_CONNECTED: {
      DBG("MQTT - Got TCP_SOCKET_CONNECTED\r\n");
      conn->state = MQTT_CONN_STATE_TCP_CONNECTED;

      process_post(&mqtt_process, mqtt_do_connect_mqtt_event, conn);
      break;
    }
    case TCP_SOCKET_DATA_SENT: {
      DBG("MQTT - Got TCP_DATA_SENT\r\n");
      conn->out_buffer_sent = 1;
      conn->out_buffer_ptr = conn->out_buffer;

      ctimer_restart(&conn->keep_alive_timer);
      break;
    }

    default: {
      DBG("MQTT - TCP Event %d is currently not manged by the tcp event callback\r\n",
          event);
    }

  }

}
Exemplo n.º 9
0
void ping_callback(void * s){
	ChannelState *state = (ChannelState *)s;
	if (state->pingOUT < 3){
		ping(state);
		ctimer_restart(&(state->timer));
		state->pingOUT++;
	}
	else {
		close_graceful(state);
		remove_channel(state->chan_num);
		state->pingOUT =0;
	}
}
Exemplo n.º 10
0
/*---------------------------------------------------------------*/
static void sample_fun(void)
{

	ctimer_reset(&ct);
	ctimer_restart(&reset_timer);


	ADC_status = adxl_sample(&sample);

	if (ADC_status == 1)
		app_conn_send((uint8_t*)&sample,ADXL_DATA_SIZE);

	PRINTF("%u,%u,%u,%u\n",sample.x.data,sample.y.data,sample.z.data,sample.vref.data);


}
Exemplo n.º 11
0
void mqtt_sn_send_pingreq(struct mqtt_sn_connection *mqc)
{
    char packet[2];

    packet[0] = 2;
    packet[1] = MQTT_SN_TYPE_PINGREQ;

    if (debug) {
        printf("Sending ping...\n");
    }

    ctimer_restart(&(mqc->send_timer));


    return send_packet(mqc, (char*)&packet, 2);
}
Exemplo n.º 12
0
static void
put_post_led_toggle_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
  static int led_state = 0;
  const uint8_t *request_content;
  int request_content_len;
  unsigned int accept = -1;

  /* Given the way the LEDs are connected to the DIO ports, the LEDs are controlled via direct DIO access. */
  content_len = 0;
  switch(led_state) {
  case (0):
    ctimer_stop(&ct);
    leds_set(LEDS_GREEN);            /* Only LEDS_GREEN on */
    CONTENT_PRINTF("Message from resource: Green LED on");
    led_state = 1;
    break;
  case (1):
    leds_set(LEDS_RED);              /* Only LEDS_RED on */
    CONTENT_PRINTF("Message from resource: Red LED on");
    led_state = 2;
    break;
  case (2):
    leds_set(0);                      /* All LEDS off */
    CONTENT_PRINTF("Message from resource: All LEDs off");
    led_state = 3;
    break;
  case 3:
    /* Both leds toggle */
    CONTENT_PRINTF("Message from resource: LEDs toggle");
    ctimer_restart(&ct);
    led_state = 0;
  default:
    break;
  }
  /* Return message */
  REST.get_header_accept(request, &accept);
  if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
    REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
    REST.set_response_payload(response, (uint8_t *)content, content_len);
  }
}
Exemplo n.º 13
0
static void
mqtt_sn_receiver(struct simple_udp_connection *sock, const uip_ipaddr_t *sender_addr, uint16_t sender_port,
         const uip_ipaddr_t *receiver_addr, uint16_t receiver_port, const uint8_t *data, uint16_t datalen)
{
  uint8_t msg_type;
  struct mqtt_sn_connection *mqc = (struct mqtt_sn_connection *)sock;
  if (mqc->keep_alive > 0 && mqc->stat == MQTTSN_CONNECTED){
    ctimer_restart((&(mqc->receive_timer)));
    printf("recieve timer reset\n");
  }
  if (datalen >= 2)
  {
    msg_type = data[1];
    switch(msg_type) {
//        case MQTT_SN_TYPE_ADVERTISE:
//        case MQTT_SN_TYPE_SEARCHGW:
//        case MQTT_SN_TYPE_GWINFO:
//        case MQTT_SN_TYPE_CONNECT:
        case MQTT_SN_TYPE_CONNACK:
          {
            memcpy(&(mqc->last_connack),data,sizeof(connack_packet_t));
            process_post(&mqtt_sn_process, connack_event, mqc);
            if(mqc->mc->connack_recv != NULL) {
              mqc->mc->connack_recv(mqc, receiver_addr, data, datalen);
            }
            break;
          }
//        case MQTT_SN_TYPE_WILLTOPICREQ:
//        case MQTT_SN_TYPE_WILLTOPIC:
//        case MQTT_SN_TYPE_WILLMSGREQ:
//        case MQTT_SN_TYPE_WILLMSG:
//        case MQTT_SN_TYPE_REGISTER:
        case MQTT_SN_TYPE_REGACK:
          {
            if(mqc->mc->regack_recv != NULL) {
              mqc->mc->regack_recv(mqc, receiver_addr, data, datalen);
            }
            manage_response(mqc, receiver_addr, data, datalen);
            break;
          }
        case MQTT_SN_TYPE_PUBLISH:
          {
            if(mqc->mc->pub_recv != NULL) {
              mqc->mc->pub_recv(mqc, receiver_addr, data, datalen);
            }
            break;
          }
        case MQTT_SN_TYPE_PUBACK:
          {
            if(mqc->mc->puback_recv != NULL) {
              mqc->mc->puback_recv(mqc, receiver_addr, data, datalen);
            }
            break;
          }
//        case MQTT_SN_TYPE_PUBCOMP:
//        case MQTT_SN_TYPE_PUBREC:
//        case MQTT_SN_TYPE_PUBREL:
//        case MQTT_SN_TYPE_SUBSCRIBE:
        case MQTT_SN_TYPE_SUBACK:
          {
            if(mqc->mc->suback_recv != NULL) {
              mqc->mc->suback_recv(mqc, receiver_addr, data, datalen);
            }
            manage_response(mqc, receiver_addr, data, datalen);
            break;
          }
//        case MQTT_SN_TYPE_UNSUBSCRIBE:
//        case MQTT_SN_TYPE_UNSUBACK:
        case MQTT_SN_TYPE_PINGREQ:
          {
            mqtt_sn_send_pingresp(mqc);
            if(mqc->mc->pingreq_recv != NULL) {
              mqc->mc->pingreq_recv(mqc, receiver_addr, data, datalen);
            }
            break;
          }
        case MQTT_SN_TYPE_PINGRESP:
          {
            if(mqc->mc->pingresp_recv != NULL) {
              mqc->mc->pingresp_recv(mqc, receiver_addr, data, datalen);
            }
            break;
          }
        case MQTT_SN_TYPE_DISCONNECT:
          {
            process_post(&mqtt_sn_process, disconnect_event, mqc);
            if(mqc->mc->disconnect_recv != NULL) {
              mqc->mc->disconnect_recv(mqc, receiver_addr, data, datalen);
            }
            break;
          }
//        case MQTT_SN_TYPE_WILLTOPICUPD:
//        case MQTT_SN_TYPE_WILLTOPICRESP:
//        case MQTT_SN_TYPE_WILLMSGUPD:
//        case MQTT_SN_TYPE_WILLMSGRESP:
        default:
          {
            if (debug) {
              printf(" unrecognized received packet...\n");
            }
            break;
          }
    }
  }
}