How to connect Particle with other cloud

Hi everyone,

I’m here want to have a discussion about how can I connect Particle Photon with other IoT platform, in my case I want to connect it with the Favoriot platform. I’ve tried to copy my ESP8266 code (which is a success to connect with the platform) and paste it into the particle. Then, I tried to code it according to the requirement of the particle. But in the process, I’ve got errors. Below is the code I’ve changed.

#include <Adafruit_DHT_Particle.h>
#include <ArduinoJson.h>
#define DHTPIN D2     // what pin we're connected to
#define DHTTYPE DHT11		// DHT 11 


const char* host = "";
String apiKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IlN5dWtyaTIyIiwicmVhZF93cml0ZSI6dHJ1ZSwiaWF0IjoxNTExNzUzMDY2f.-yOeZT0x59kuRgD72cI9EhrGim6sgndOoErzVqKU8lI";
String device_developer_id = "deviceDefault@Syerlac22";

int loopCount;

void setup() {
	Particle.publish("DHTxx test!");
	Particle.publish("state", "DHTxx test start");

	//loopCount = 0;

void loop() {
	float h = dht.getHumidity();
	float t = dht.getTempCelcius();
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t)) {
		Particle.publish("Failed to read from DHT sensor!");

	Particle.publish("readings", String::format("{\"Hum(\%)\": %4.2f, \"Temp(°C)\": %4.2f}", h, t));
  Particle.publish("connecting to :");
  //WiFiClient client;
  const int httpPort = 80;
  if (!Particle.function(host, httpPort)) {
    Particle.publish("connection failed");
  String url = "/v1/streams";
  Particle.publish("Requesting URL: ");

  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["device_developer_id"] = device_developer_id;

  JsonObject& data = root.createNestedObject("data");
  data["temperature"] = t;
  data["humidity"] = h;

  char buffer[200];  //converting object to character
  root.printTo(buffer, sizeof(buffer));

  Particle.publish(String("POST ") + url + " HTTP/1.1\r\n" +
               "host: " + host + "\r\n" + 
               "apikey: " + apiKey + "\r\n" + 
               "content-type: application/json\r\n" + 
               "cache-control: no-cache\r\n" + 
               "content-length: " + root.measureLength() + "\r\n" + 
               "connection: close\r\n\r\n" + String(buffer) + "\r\n");
  unsigned long timeout = millis();
  //while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Particle.publish(">>> Client Timeout !");
    String line = Particle.readStringUntil('\r');
 // }
  Particle.publish("closing connection");

Please, anyone, help me to solve this issue and discuss more on how to connect Particle with another cloud.

Particle.function() hasn’t got a valid place in loop() and your Particle.publish() calls will probably violate the rate limit.

If I look at the Particle document, yes, the Particle.function() is not in the loop.
What do you mean about my Particle.publish() calls will probably violate the rate limit?
Can you explain more about it?

There are certain limits to the amount of publishes you can send in a given time frame. I’d you check the respective docs, you’ll notice it’s been documented :slight_smile:

1 Like

Sir, this one right?

public/private (default public)
ttl (time to live, 0–16777215 seconds, default 60) !! NOTE: The user-specified ttl value is not yet implemented, so changing this property will not currently have any impact.
optional data (up to 255 bytes)

But sir, I do not see the error is about Particle.publish().
Below are the errors.

lib/ArduinoJson/ArduinoJson/Data/ValueSetter.hpp:22:17: no match for ‘operator=’ (operand types are ‘ArduinoJson::JsonVariant’ and ‘const String’)

28_nov_dht_favo.ino:49:41: no matching function for call to ‘CloudClass::connected(const char*&, const int&)’

28_nov_dht_favo.ino:82:69: no matching function for call to ‘CloudClass::connected(StringSumHelper&)’

I think that I’ve got a problem about how to command to another cloud. I would like to know your opinion.


As far as the limits are concerned, this is the interesting part:
“NOTE 1: Currently, a device can publish at rate of about 1 event/sec, with bursts of up to 4 allowed in 1 second. Back to back burst of 4 messages will take 4 seconds to recover.”

As for your errors, it seems that the ArduinoJSON library has some issues. Is that ported correctly for Particle? (Where did you get it?)

Actually, the ArduinoJSON is in the Particle’s library.

can you suggest me the correct way of doing it? I mean how to connect Particle with another cloud.

Right now, I’m still trying to solve the problem.

When I compile your code - which won’t work due to the reasons mentioned - I get different errors

../wiring/inc/spark_wiring_cloud.h:194:25: no matching function for call to 'CloudClass::_function(const char* const&, int&)'

../wiring/inc/spark_wiring_cloud.h:194:25: invalid conversion from 'int' to 'int (*)(String)' [-fpermissive]

lib/ArduinoJson/ArduinoJson/Data/ValueSetter.hpp:22:17: no match for 'operator=' (operand types are 'ArduinoJson::JsonVariant' and 'const String')

dummy.ino:82:16: 'class CloudClass' has no member named 'stop'

dummy.ino:89:28: 'class CloudClass' has no member named 'readStringUntil'

dummy.ino:93:20: no matching function for call to 'CloudClass::publish()'

and at least the first two and last three could be solved by actually reading the docs - the fist number after the filename (e.g. dummy.ino:82:16) is the line number in your code.
If a function does not exist - or expects a different parameter list than provided - it shouldn’t be surprising to get these errors.
We can help with “complicated” problems but we haven’t got the time to spoon feed trivials.

The only non-obvious error is the one about the JSON library. But by pressing the SHOW RAW button extra info pops up (this is what we’d need posted to actually address the issue) and reveals the actual location in your code.
This error refers to line 59 in your code

  root["device_developer_id"] = device_developer_id;

and can be cured this way

  root["device_developer_id"] = (const char*)device_developer_id;

I will note the above.
Thank you, sir.

Regarding the JSON library, I need an information about it. Doesn’t Particle was embedded with the command of JSON to publish data? Then, why there is JSON library needed?

Not really, you can use Particle.publish in combination with a “webhook” defined in the particle cloud that will format your data into JSON before handing it on to another site/cloud service. There’s a significant advantage in this, it keeps the comms secure as device->particle is encrypted while the http based device->favoriot is not, and it makes the cloud do the hardwork in addition it means your api key and id can be stored in the webhook definition rather than compiled into your firmware. I would think you could probably use that approach but I know nothing of favoriot and yours appears to be the first mention of that service on here.

1 Like

Yes, the Favoriot is the new IoT platform.
Yes, I’ve known the “webhook”. But I still not go further into that.
Alright then. I will consider your suggestion as the backup plan.

Hi Viscacha…
I’ve tried your suggestion as a backup plan. I’ve created the webhook, but it seems I’ve got something else, not an error but misunderstand. Can you check it for me?

my console shows this, why is it go to thingSpeak?

and I’m using the coding given at the doc.

int led = D6; // The on-board LED

void setup() {
pinMode(led, OUTPUT);

void loop() {
digitalWrite(led, HIGH); // Turn ON the LED

String Test_DHT11 = String(random(60, 80));
Particle.publish(“temp”, Test_DHT11, PRIVATE);
delay(30000); // Wait for 30 seconds

digitalWrite(led, LOW); // Turn OFF the LED
delay(30000); // Wait for 30 seconds

Your event should be “Test_DHT11” and not “temp”.
The event name you publish must match the event name stated in the webhook declaration.

Again a trivial error that could be solved my minimal observation.

1 Like

Ooo… ok. Got it.