Introduction: How to Send Data to the Cloud With Arduino Ethernet

About: IoT Maker, co-founder of asksensors.com

This instructable shows you how to publish your data to AskSensors IoT Platform using Arduino Ethernet Shield. The Ethernet Shield enables your Arduino to easily get connected to the cloud, send and receive data with an internet connection.

What we will learn:

We will be learning the basics of connecting an Arduino Ethernet shield to the AskSensors web server, and sending dummy data over HTTP requests. At the end, will visualize live data streams in the AskSensors cloud.


Why HTTP and not HTTPS?

AskSensors supports HTTPS, however, MCUs mounted on Arduinos don't handle HTTPS connections. For this reason we will be using HTTP instead of HTTPS.

Note : If you prefer MQTT protocol, please visit this page : Connect Arduino Ethernet To AskSensors Over MQTT

Step 1: Arduino Ethernet Shield

Hardware Features:

  • Requires an Arduino board.

  • Operating voltage 5V, supplied from the Arduino Board.

  • Ethernet Controller: Wiznet Ethernet controller W5100 with internal 16K buffer

  • The Wiznet W5100 provides a network (IP) stack capable of both TCP and UDP.

  • Connection speed: up to 10/100Mb

  • Connection with Arduino on SPI port: It uses the ICSP header pins and pin 10 as chip select for the SPI connection to the Ethernet controller chip.

  • The latest revision of the Ethernet Shield includes a micro-SD card slot on board, which can be used to store files for serving over the network.

  • The Ethernet Module has a standard RJ45 connection, with an integrated line transformer.

  • The connection to a network is made with a RJ45 Ethernet cable.


Software Library:

    • The Ethernet shield relies on the Arduino Ethernet library.
    • The library comes bundled with the Arduino IDE.
    • We will need to change some network settings in the program to correspond to our network.


    Informational LEDs:

    Later, you may need to verify the Ethernet status using the informational LEDs:

    • PWR: indicates that the board and shield are powered
    • LINK: indicates the presence of a network link and flashes when the shield transmits or receives data
    • FULLD: indicates that the network connection is full duplex
    • 100M: indicates the presence of a 100 Mb/s network connection (as opposed to 10 Mb/s)
    • RX: flashes when the shield receives data
    • TX: flashes when the shield sends data
    • COLL: flashes when network collisions are detected

    Step 2: Materials We Need

    The hardware required for this tutorials is:

    1. A computer running Arduino IDE software.

    2. An Arduino board such as the Arduino Uno.

    3. An Arduino Ethernet shield.

    4. A USB cable for powering and programming the Arduino.

    5. An Ethernet cable, for connecting to your network router.

    Step 3: Setup AskSensors

    AskSensors requires the following:

    • Create a user account: You can get one for free (https://asksensors.com)
    • Create a Sensor: A sensor is a communication channel with a unique Api Key where AskSensors collects and stores user's data.

    Each Sensor provides several Modules that the user can send data to them separately. The user can also visualize the collected data of each module in a graph. AskSensors provides multiple choices of graphs including Line, Bar, Scatter and gauge.

    Step 4: Coding

    So at this moment we have been able to register a new Sensor in the AskSensors platform, Now we are going to write some code in the Arduino for its connection to the platform. There are hundreds of tutorials about connecting the Arduino to the web through the Ethernet Shields, so I'm not going to explain this part.

    Download this Arduino sketch example from github. The code uses DHCP and DNS for the server and is supposed to work right away with few changes:

    1. If you are using more than one Ethernet shield on a network, make sure that each Ethernet shield on the network must have a unique mac address.
    2. Change the IP address in the sketch to match the IP address range of your network.
    3. Set the Api Key In of your sensor (given by AskSensors in the previous step)
    4. Set your dummy data.

    // MAC
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
    // Set the static IP address to use if the DHCP fails to assign 
    IPAddress ip(192, 168, 1, 177);
    // ASKSENSORS config. 
    const char* apiKeyIn = "MTWN7AQOLWJNEIF8RGMAW5EGKQFAHN2K"; // Change it with your API KEY IN
    // dummy data
    int dumData = 100; // set your data
    

        Step 5: Programming

        1. Plug the Ethernet shield into the Arduino Uno board.
        2. Connect the Ethernet shield to your router/network through the Ethernet cable.
        3. Connect the Arduino to the computer through the USB cable. Power will be supplied to the two boards via the USB cable.
        4. Open your code in Arduino IDE, Select the correct Arduino board and COM port. Then, upload the code to your Arduino board. make sure that the code was uploaded successfully.

        Step 6: Running the Code

        • Reset: You can use the reset button on the shield to reset both the the Ethernet Controller and the Arduino board.
        • Run the code: After reset/power up, open a serial terminal, you should see the Arduino printing the program status: the arduino connects to the network (takes few seconds), then sends the dummy data to the AskSensors over HTTP get requests.
        • Server Response: After receiving the request of wrting data to the specific Sensor from the client, the server first sends a HTTP response telling the number of modules updated successfully ('1' in our case).

        Step 7: Visualize Data

        Now that your data is published well to the AskSensors cloud. You can see this data in graph or export it to CSV file.

        Each Sensor has its own dashboard that currently allows monitoring its state in real time(last update date, connection state ..).

        Click your Sensor from the list, set a graph to your module (Module 1). The image above shows an example of display using the gauge graph type.

        Step 8: Well Done!

        Thank you for reading. you can find more tutorials here.

        If you have any queries, join the AskSensors community!