예제 #1
0
파일: main.cpp 프로젝트: 10to7/ntp-arduino
static void write_status_page(BufferFiller &response)
{
    char buffer[32];

    response.emit_p(PSTR(
        "HTTP/1.0 200 OK\r\n"
        "Content-Type: text/html\r\n"
        "Pragma: no-cache\r\n"
        "\r\n"
        "<meta http-equiv='refresh' content='1'/>"
        "<title>Jystic NTP Server v0.1</title>"));

    print_gps_time(buffer);
    response.emit_p(PSTR("<h1>UTC $S<h1>"), buffer);

    response.emit_p(PSTR("Running $S\n"),
        print_ms_time(millis(), buffer));

    response.emit_p(PSTR("Free mem $D\n"),
        get_free_memory() );

    uint32_t time_since_pps = micros() - g_pps_time;
    response.emit_p(PSTR("Since PPS $S\n"),
        print_ms_time(time_since_pps/1000, buffer));
}
예제 #2
0
파일: home.cpp 프로젝트: konfiot/Dohome
bool Home::fillJSONData(BufferFiller &buf){      
      buf.emit_p(PSTR("\"h\":{\"n\":\"$S\",\"p\":["), _name);
      
      for (byte i = 0 ; i < _pieces.size() ; i++){
        if (i > 0) buf.emit_p(PSTR(","));
        _pieces[i]->fillJSONData(buf);
      }
      
      buf.emit_p(PSTR("]}"));
    return true;
}
예제 #3
0
static uint16_t homePage() {
  long t = millis() / 1000;
  word h = t / 3600;
  byte m = (t / 60) % 60;
  byte s = t % 60;
  bfill = ether.tcpOffset();
  bfill.emit_p(PSTR(
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n"
    "\r\n"
    "<meta http-equiv='refresh' content='1'/>"
    "<title>RBBB server</title>"
    "<h1>$D$D:$D$D:$D$D</h1>"),
      h/10, h%10, m/10, m%10, s/10, s%10);
  return bfill.position();
}
예제 #4
0
static word serverRequestTemperature(byte fd) {
	// filling state
	uint8_t data[16] = {0}; // 16 bytes block for encryption, which have to be send in hex
	data[0] = uint8_t(uint32_t(sharedState->currentTemperature)); // whole part 
	data[1] = uint8_t(uint32_t(sharedState->currentTemperature * 100) % 100); // fraction part
	*(uint32_t*)(data + (16 - sizeof(uint32_t))) = sharedState->lastNonce;

	sharedState->lastNonce += 1;
	
	// encrypting the state
	aes128_enc_single(encKey, data);

	printlnDebug("Sending encrypted state");
	BufferFiller bfill = ether.tcpOffset();
	bfill.emit_p(sendTemperatureHeader);
	bfill.emit_raw((char*)data, sizeof(data)); 
	temperatureSend = 1;
	sendEaseTime = millis() + SENDINGEASE;
	return bfill.position();
}
예제 #5
0
void GetWeather() {
  // check if we've already done dns lookup
  if(ether.hisip[0] == 0) {
    ether.dnsLookup(website);
  }

  //bfill=ether.tcpOffset();
  char tmp[30];
  read_from_file(wtopts_name, tmp, 30);
  BufferFiller bf = (uint8_t*)tmp_buffer;
  bf.emit_p(PSTR("$D.py?loc=$E&key=$E&fwv=$D&wto=$S"),
                (int) os.options[OPTION_USE_WEATHER].value,
                ADDR_NVM_LOCATION,
                ADDR_NVM_WEATHER_KEY,
                (int)os.options[OPTION_FW_VERSION].value,
                tmp);
  // copy string to tmp_buffer, replacing all spaces with _
  char *src=tmp_buffer+strlen(tmp_buffer);
  char *dst=tmp_buffer+TMP_BUFFER_SIZE-1;
  
  char c;
  // url encode. convert SPACE to %20
  // copy reversely from the end because we are potentially expanding
  // the string size 
  while(src!=tmp_buffer) {
    c = *src--;
    if(c==' ') {
      *dst-- = '0';
      *dst-- = '2';
      *dst-- = '%';
    } else {
      *dst-- = c;
    }
  };
  *dst = *src;
  
  uint16_t _port = ether.hisport; // save current port number
  ether.hisport = 80;
  ether.browseUrl(PSTR("/weather"), dst, website, getweather_callback);
  ether.hisport = _port;
}
예제 #6
0
void GetWeather() {
  // perform DNS lookup for every query
  nvm_read_block(tmp_buffer, (void*)ADDR_NVM_WEATHERURL, MAX_WEATHERURL);
  ether.dnsLookup(tmp_buffer, true);

  //bfill=ether.tcpOffset();
  char tmp[30];
  read_from_file(wtopts_filename, tmp, 30);
  BufferFiller bf = (uint8_t*)tmp_buffer;
  bf.emit_p(PSTR("$D.py?loc=$E&key=$E&fwv=$D&wto=$S"),
                (int) os.options[OPTION_USE_WEATHER],
                ADDR_NVM_LOCATION,
                ADDR_NVM_WEATHER_KEY,
                (int)os.options[OPTION_FW_VERSION],
                tmp);
  // copy string to tmp_buffer, replacing all spaces with _
  char *src=tmp_buffer+strlen(tmp_buffer);
  char *dst=tmp_buffer+TMP_BUFFER_SIZE-12;
  
  char c;
  // url encode. convert SPACE to %20
  // copy reversely from the end because we are potentially expanding
  // the string size 
  while(src!=tmp_buffer) {
    c = *src--;
    if(c==' ') {
      *dst-- = '0';
      *dst-- = '2';
      *dst-- = '%';
    } else {
      *dst-- = c;
    }
  };
  *dst = *src;
  
  uint16_t _port = ether.hisport; // save current port number
  ether.hisport = 80;
  ether.browseUrl(PSTR("/weather"), dst, PSTR("*"), getweather_callback);
  ether.hisport = _port;
}
예제 #7
0
void GetWeather() {
  EthernetClient client;

  static struct hostent *server = NULL;
  if (!server) {
    strcpy(tmp_buffer, WEATHER_SCRIPT_HOST);
    server = gethostbyname(tmp_buffer);
    if (!server) {
      DEBUG_PRINTLN("can't resolve weather server");
      return;    
    }
    DEBUG_PRINT("weather server ip:");
    DEBUG_PRINT(((uint8_t*)server->h_addr)[0]);
    DEBUG_PRINT(":");
    DEBUG_PRINT(((uint8_t*)server->h_addr)[1]);
    DEBUG_PRINT(":");
    DEBUG_PRINT(((uint8_t*)server->h_addr)[2]);
    DEBUG_PRINT(":");
    DEBUG_PRINTLN(((uint8_t*)server->h_addr)[3]);
  }

  if (!client.connect((uint8_t*)server->h_addr, 80)) {
    DEBUG_PRINTLN("failed to connect to weather server");
    client.stop();
    return;
  }

  BufferFiller bf = tmp_buffer;
  char tmp[100];
  read_from_file(wtopts_name, tmp, 100);
  bf.emit_p(PSTR("$D.py?loc=$E&key=$E&fwv=$D&wto=$S"),
                (int) os.options[OPTION_USE_WEATHER].value,
                ADDR_NVM_LOCATION,
                ADDR_NVM_WEATHER_KEY,
                (int)os.options[OPTION_FW_VERSION].value,
                tmp);    

  char *src=tmp_buffer+strlen(tmp_buffer);
  char *dst=tmp_buffer+TMP_BUFFER_SIZE-1;
  
  char c;
  // url encode. convert SPACE to %20
  // copy reversely from the end because we are potentially expanding
  // the string size 
  while(src!=tmp_buffer) {
    c = *src--;
    if(c==' ') {
      *dst-- = '0';
      *dst-- = '2';
      *dst-- = '%';
    } else {
      *dst-- = c;
    }
  };
  *dst = *src;

  char urlBuffer[255];
  strcpy(urlBuffer, "GET /weather");
  strcat(urlBuffer, dst);
  strcat(urlBuffer, " HTTP/1.0\r\nHOST: weather.opensprinkler.com\r\n\r\n");
  
  client.write((uint8_t *)urlBuffer, strlen(urlBuffer));
  
  bzero(ether_buffer, ETHER_BUFFER_SIZE);
  
  time_t timeout = os.now_tz() + 5; // 5 seconds timeout
  while(os.now_tz() < timeout) {
    int len=client.read((uint8_t *)ether_buffer, ETHER_BUFFER_SIZE);
    if (len<=0) {
      if(!client.connected())
        break;
      else 
        continue;
    }
    peel_http_header();
    getweather_callback(0, 0, ETHER_BUFFER_SIZE);
  }
  client.stop();
}
예제 #8
0
void print_json_header(bool bracket=true) {
  bfill.emit_p(PSTR("$F$F$F$F\r\n"), html200OK, htmlContentJSON, htmlAccessControl, htmlNoCache);
  if(bracket) bfill.emit_p(PSTR("{"));
}
예제 #9
0
void print_html_standard_header() {
  bfill.emit_p(PSTR("$F$F$F$F\r\n"), html200OK, htmlContentHTML, htmlNoCache, htmlAccessControl);
}