Help connecting devices using ESP8266

Hi there,

I’m trying to connect my ESP8266, but i don’t know what i did wrong, it doesn’t connect the device.
Can any one help me pls. (i’m using v 1.6.9 and an arduino mega 2560)
Here is my code:

#include "DHT.h"
#include <LiquidCrystal_I2C.h>
#include <NewPing.h>

#include <SPI.h>
#include <WiFi.h>
#include <ThingerWifi.h>
 
#define DHTPIN 22 //pin no arduino
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
#define fan 4


#define TRIGGER_PIN  41
#define ECHO_PIN     40
#define MAX_DISTANCE 300

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

ThingerWifi thing("My ID", "My Device ID", "My Device Pass");

//LiquidCrystal_I2C lcd(0x27, 20, 4);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

int maxHum = 60;
int maxTemp = 40;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  pinMode(fan, OUTPUT);
  dht.begin();
  //Serial.begin(9600);

  thing.add_wifi("My Wi-Fi", "My Wi-Fi Pass");
  thing["millis"] >> outputValue(millis());
  
  lcd.begin(20, 4); //Start LCD
  //lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home (); // go home on LCD
  lcd.print("Green House v0.1");
  lcd.clear();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);
 // lcd.clear();

 thing.handle();

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    lcd.println("Failed to read from DHT sensor!");
    return;
  }

  if (h > maxHum || t > maxTemp) {
    digitalWrite(fan, HIGH);
  } else {
    digitalWrite(fan, LOW);
  }

 // delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  int distance = sonar.convert_cm(uS);
   
 //Calculate the distance (in cm) based on the speed of sound.
//long distance = duration/58.2;


  lcd.setCursor(0, 2);
  lcd.print("Hum: ");
  lcd.print(h);
  lcd.print("%");
  lcd.setCursor(0, 1);
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print((char)223);
  lcd.print("C ");
  lcd.setCursor(0, 3);
  lcd.print("Water: ");
  if (distance == 0) { lcd.print("Error!");} else{
  lcd.print(distance); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
  lcd.print(" cm  ");}

}

Hello JRFerreira!
if I uderstand you… U are trying to connect an Arduino mega 2560 trhought an ESP8266?
Thinger.io ESP libraries don’t implement this funccionallity yet, there are only ready to run in the ESP8266 processor, so if you want to do it try to make this:

First load a basic thinguer.io ESP8266 sketch in the wifi board, and create on it a serial comunication port ready to recibe data from the mega and upload it to thinger server, or get messages from the server and send it to the mega.
And thrn create another serial com in the mega sketcht
Finally connect those serial ports and try it.

I think that it is a very instesting project, if you make it work, please write! if not… may be I will write a tutorial when I have some free time XD