Monday, April 6, 2015

IoT experience: Arduino Uno + Ethernet Shield send data to and

It's a IoT experience, run on Arduino Uno + Ethernet Shield, read analog input from A0, send to and

VIew on is simple publishing and subscribing for machines, sensors, devices, robots, and gadgets (we just call them things). We call published messages ‘dweets’. It’s helpful to think of as a Twitter for things, in fact.

With, we can create simple dashboards for devices, include things.

The code on Arduino Uno, AnalogInDweetIoRepeat.ino. Modified from Web Client Repeating example (


#include <SPI.h>
#include <Ethernet.h>

const int analogIn = A0;
int analogVal = 0;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
IPAddress ip(192, 168, 1, 177);

// initialize the library instance:
EthernetClient client;

char server[] = "";

unsigned long lastConnectionTime = 0;             // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
// the "L" is needed to use long type numbers

void setup() {
  // start serial port:
  Serial.println("--- Start ---");
  // give the ethernet module time to boot up:
  // start the Ethernet connection using a fixed IP address and DNS server:
  Ethernet.begin(mac, ip); 
  // print the Ethernet board/shield's IP address:
  Serial.print("My IP address: ");

void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c =;

  // if ten seconds have passed since your last connection,
  // then connect again and send data:
  if (millis() - lastConnectionTime > postingInterval) {


// this method makes a HTTP connection to the server:
void httpRequest() {
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield

  // if there's a successful connection:
  if (client.connect(server, 80)) {
    analogVal = analogRead(analogIn);
    // Make a HTTP request:
    String s = "POST /dweet/for/arduinotest?A0=";
    client.println("Connection: close");

    // note the time that the connection was made:
    lastConnectionTime = millis();
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");

This video show how it run and view on and Pin A0 is open(float) here, so the value is random.

Related example on my another blog about Raspberry Pi:
IoT at, Python on RPi 2 to send data to Cloud
- Create dashboards for things with

- Arduino Due + ESP8266 + DHT11, to update

NodeMCU version:
NodeMCU act as WiFi client to update

Somebody complain the example not work, I tried agin, Arduino Uno + Ethernet Shield, without change. And found it still work as expected.

Once you make it run, you can check the thing at


  1. Hi~ yesterday I left my comment, but can't see it. Did you got it? so I write again.
    It's very good project. so, If you don't mind, I would like to introduce on WIZnet museum for everyone.
    WIZnet produce the W5100 on Ethernet shield. Hopefully, you will allow this.
    and one more thing to say, I have almost made a new W5500 Ethernet shield.
    if you have interest, then I could send free sample when it releases. just send your address to my email I think, it is good for your future experiment :). Thanks.~

  2. Hello Bongjun Hur,

    Strange, I can't see your comment yesterday.

    For sure, you are welcome to introduce my exercise on WIZnet museum.


  3. Dear Eric, as your content, I followed the step and I've made mbed project as like yours.
    you can see the code & some pics
    Thanks again :).

  4. Hi, I'm trying it with a temperature which requires some calculation before posting. But it seems that it it not able to concate the value. Can you please suggest what the problem maybe?

    1. hello,

      what you means "not able to concate the value"?

  5. Hi Eric,
    I am impressed with your post. I have copied your code as-is above. I changed my "thing name" from ' "POST /dweet/for/arduinotest?A0="; ' to a unique name. I made no other changes to your code since my Arduino is also on 192.168.1.x network.
    I am unable to duplicate your results.
    Using Wireshark, I am unable to see any post data being transmitted. Can you help?

  6. Hi, two weeks ago everything works well (ethernet shield correctly sent the request to iot server) but not now send more. I tried two different ethernet shield and is the same. Will you help me please?

  7. Thanks for this. Just the background I needed to get my Uno on-line. Much appreciated. Worked first time, and updated it to send a loop counter parameter for some "live" test data. Now to get the temperature sensor hooked up and have some real data.

    I haven't looked, but it seems as though you just assign a MAC address to the ethernet shield. There was certainly no sticker on mine with one. So I just used your default and it worked. Changed the IP to match my network/router.

  8. hello Andrew Moizer,

    As I remember (I'm not sure), the very early version Ethernet Shield have no individual MAC address, you can use the default setting. Or, may be you can assign it by yourself.

    1. I'll see what I can find. I bought the shield a year ago from Banggood. It seems to be working just fine right now. It would be mighty bad luck to get a MAC address conflict on a home LAN. Once again, thanks for sharing your examples. Got me going in no time.

  9. why is connection showing failed everytime???? possible reasons

  10. Could you possibly post how you set up the content? Thanks.