Arduino yun send and receive data from an external web api

Hello

I'm a beginner with arduino yun and would like to know if it is possible to use arduino yun to send and get data from a web api hosted on an internet server?

For example, currently my project reads the values ​​from a scale when a request is received (htttp://ip-arduino-yun/arduino/scale). I would like to make the arduino send continuously the values ​​read from the scale to an api.

Any examples or tips?


#include <Bridge.h>
#include <BridgeServer.h>
#include <BridgeClient.h>

BridgeServer server;

void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  Bridge.begin(); //pode ficar bloqueado por até 2 segundos
  digitalWrite(13, HIGH);

  server.listenOnLocalhost();
  server.begin();
}

void loop() {

  BridgeClient client = server.accept();

  if (client) {
    process(client);
    client.stop();
  }
}

void process(BridgeClient client) {
  String command = client.readStringUntil('&');

  if (command == "scale") {
    readScale(client);
  }
}

void readScale(BridgeClient client) {
  client.println("Scale: 350g");
}

I suggest making use of the powerful Linux side of the Yun. Use a Process object from the Bridge library to make a curl call to your API. The Process object can call curl directly, or better yet it can call a Python (or other language) script to preprocess/format/postprocess the data rather than do everything in the sketch.

Remember, the Yun is much more than an little 8-bit Atmel processor running your sketch - the Linux side is a powerful Linux system at your disposal, it is so much more than a simple network interface.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.