Things used in this project

Hardware components:
D1 mini
Everything ESP Wemos D1 Mini
×1
Software apps and online services:
Ide web
Arduino IDE
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Custom parts and enclosures

Schematics

Code

HTTP Post with EXP ProtocolC/C++
// send a HTTP Post to the backend, using the EXP protocol
bool sendSensorData (uint32_t seconds, float temperature, String userId, String userKey, uint32_t devId) {
  Serial.println("sendSensorData " + String(seconds) + " " + String(temperature) + " " + userId + " device:" + String(devId, HEX));
  // prepare post data
  String postUrl = String(ID_TIME_SECONDS) + "/" + String(seconds, DEC) + "/" + String(ID_VERSION_HW) + "/" + String(VER_HW, DEC) + "/" +  String(ID_VERSION_SW) + "/" + String(VER_SW, DEC) + "/" + String(ID_TEMPERATURE_CELSIUS) + "/" + String(temperature);
  Serial.println(postUrl);
  // prepare http client to do the post
  HTTPClient http;
  // data is sent as URL / RESTful API
  http.begin(URADMONITOR_SERVER + postUrl);
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  // the expProtocol requires these customs headers
  http.addHeader("X-User-id", userId);
  http.addHeader("X-User-hash", userKey);
  http.addHeader("X-Device-id", String(devId, HEX));
  int httpCode = http.POST("");
  // check server results
  if (httpCode != 200) {
    Serial.println("not successful");
    http.end();
    return false;
  } else {
    char buffer[200] = {0};
    http.getString().toCharArray(buffer, 200);
    Serial.print("Server response:"); Serial.println(buffer);
    // check response
    char value[10] = {0}; // this has to be inited, or when parsing we could have extra junk screwing results
    if (jsonKeyFind(buffer, "setid", value, 10)) {
      Serial.print("Server allocated new ID:"); Serial.println(value);
      deviceID = hex2int(value);
      eeprom_write_dword(EEPROM_ADDR_DEVID, deviceID);
      EEPROM.commit();
    } 
    http.end();
    return true;
  }
}

Credits

Radu
Radu Motisan
0 projects • 7 followers
By training I'm a software engineer. By hobby I'm a chemist, physicist and electronics amateur.
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog