• 1
    Step 1

    Serial communication

    After soon 60 years the RS-232 standard is doing strong, as that's what we're talking with to our most modern IoT thingys (yep I know about TTL vs positive/negative levels, pretty close anyway I'd say). Pretty much any MCU board talks RS-232 to the computer, nowadays generally through a UART inside the MCU board or cable, thus the Serial library is probably the most common denominator that's always available for I/O.

    nitialization

    None needed

    Setup()

      Serial.begin(115200); //9600 would be more common, but now and then a tad slow
    

    Use

    //Output
        Serial.println("hello"); //With line feed 
        Serial.print((String)"Temperature: " + temp + " humidity: " + humidity); //String library handles concatenating 
    
    // Input two comma separated integers. Note: This simple version blocks CPU, if needs to wait (default 1 sec) for another integer.
        if (Serial.available() > 0)
          if (Serial.peek() > 42) { //Ignore LF,CR etc
            userInput1 = Serial.parseInt(); //Adjust number of these as needed
            userInput2 = Serial.parseInt();
          } else {
            Serial.readString(); //Ditch useless data
          }

  • 2
    Step 2

    Network connectivity - TCP/IP and HTTP

    For pretty much any ESP project I'd want the data to be sent to somewhere, thus networking would be like garlic in cooking - first chop it and then start wondering what are you actually going to cook.


    Initialization

    const char *WLAN_SSID = "My-network-SID-address";
    const char *WLAN_PASSWORD = "My-network-pw";
    HTTPClient http;

    Setup()

    WiFi.mode(WIFI_STA);
    WiFi.begin(WLAN_SSID, WLAN_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) { 
        delay(200);
        Serial.print(".");
    }
    Serial.println((String)"\nConnected: " + WiFi.localIP() + " RSSI: " + WiFi.RSSI());

    Use (HTTP GET call)

    // Helper function
    int doHttpGet(String url) {
        int httpCode = -1;
        for(int i = 0; i < 20; i++) {
        http.begin(url.c_str());
        int httpCode = http.GET();
        http.end();
        Serial.println((String)"URL: " + url);
        Serial.println((String)"HTTP return code: " + httpCode + " " + http.errorToString(httpCode));
        if(httpCode > 0) //Other retry codes can be added
            break;
            delay(5000);
        }
        return httpCode;
    }
    
    // Do the request:
        doHttpGet("http://my.url?val1=42&val2=43";
    
  • 3
    Step 3

    ThingspeakValues from all the sensors need to be sent somewhere to be visualized and processed. Thingspeak is a great free-for-hobbyists platform for that, you can store up to 3M measurements for one year, do all the possible processing with Matlab and easily visualize the stuff. Plus, you can any time easily export your data, should they change their hobbyist pricing policy or for long time storing.


    These snippets require the networking ones from the previous section.

    Initialization

    #define THINGSPEAK_URL "http://api.thingspeak.com/update?api_key=";
    #define THINGSPEAK_KEY "YOURCHANNELKEYHERE"

    Setup()

    Nothing for Thingspeak - networking obviously needed, see previous section.

    Use

    // Helper function
    int sendHttpThingspeak(float v1=0,float v2=0,float v3=0,float v4=0,float v5=0,float v6=0,float v7=0,float v8=0) {
        String url = (String)THINGSPEAK_URL+THINGSPEAK_KEY+"&field1="+v1+"&field2="+v2+
            "&field3="+v3+"&field4="+v4+"&field5="+v5+"&field6="+v6+"&field7="+v7+"&field8="+v8;
        return doHttpGet(url);
    }
    
    // To send the data (max 8 values):
    sendHttpThingspeak(temp1,humi1,pressure,humidity,WiFi.RSSI());