Beispiel #1
0
uint8_t
sms77_send(char *status)
{
  /* Transmission taking action */
  if (sms77_tmp_buf) return 0;

  uint8_t len = strlen(status);
  if (len > 160) {
    SMSDEBUG("message too long: cropping");
    len = 160;
  }

  sms77_tmp_buf = malloc(160);
  if (!sms77_tmp_buf) return 0;

  memcpy(sms77_tmp_buf, status, len);
  sms77_tmp_buf[len] = 0;

  uip_ipaddr_t *ipaddr;
  if (!(ipaddr = resolv_lookup(CONF_SMS77_SERVICE))) {
    resolv_query(CONF_SMS77_SERVICE, sms77_dns_query_cb);
  } else {
    sms77_dns_query_cb(NULL, ipaddr);
  }
  return 1;
}
Beispiel #2
0
int16_t parse_cmd_user (char *cmd, char *output, uint16_t len)
{
	SMSDEBUG ("username\n");
	while (*cmd == ' ')
	cmd++;

    if (*cmd != '\0') {
		memset(sms77_user, 0, SMS77_VALUESIZE);
		memcpy(sms77_user, cmd, SMS77_VALUESIZE);
		eeprom_save(sms77_username, cmd, strlen(cmd));
		eeprom_update_chksum();
		SMSDEBUG ("set new : %s\n",cmd);
		return ECMD_FINAL_OK;
    }
    else {
    	SMSDEBUG ("get current : %s\n ",sms77_user);
		return ECMD_FINAL(snprintf_P(output, len, PSTR("%s"), sms77_user));
    }	
}
Beispiel #3
0
static void
sms77_dns_query_cb(char *name, uip_ipaddr_t *ipaddr) {
  SMSDEBUG("got dns response, connecting\n");
  if(!uip_connect(ipaddr, HTONS(80), sms77_net_main)) {
    if (sms77_tmp_buf) {
      free(sms77_tmp_buf);
      sms77_tmp_buf = NULL;
    }
  }

}
Beispiel #4
0
static void
sms77_net_main(void)
{	
	
    if (uip_aborted() || uip_timedout()) {
	SMSDEBUG ("connection aborted\n");
        if (sms77_tmp_buf) {
          free(sms77_tmp_buf);
          sms77_tmp_buf = NULL;
        }
        return;
    }

    if (uip_closed()) {
	SMSDEBUG ("connection closed\n");
        if (sms77_tmp_buf) {
          free(sms77_tmp_buf);
          sms77_tmp_buf = NULL;
        }
        return;
    }


    if (uip_connected() || uip_rexmit()) {
	SMSDEBUG ("new connection or rexmit, sending message\n");
        char *p = uip_appdata;
        p += sprintf(p,  "GET /?u=%s&p=%s&to=%s&type=%s&text=", sms77_user, sms77_pass, sms77_recv, sms77_type);
        p += urlencode(sms77_tmp_buf, strlen(sms77_tmp_buf), p);
        p += sprintf_P(p, sms77_secheader);
        uip_udp_send(p - (char *)uip_appdata);
        SMSDEBUG("send %d bytes\n", p - (char *)uip_appdata);
    }

    if (uip_acked()) {
      uip_close();
    }
    
    if (uip_newdata())
    	SMSDEBUG("data: %s\n", uip_appdata);

}