0

Map not working
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Map not working

by pcborges on Sun Aug 18, 2019 8:34 am

Hi, I set temp and humidity sensor data and a remote control led in my dashboard and everything works ok.
Map always show New York although I am half a world away...
What can I be doing wrong?
Thanks

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Re: Map not working

by brubell on Mon Aug 19, 2019 10:12 am

pcborges wrote:Hi, I set temp and humidity sensor data and a remote control led in my dashboard and everything works ok.
Map always show New York although I am half a world away...
What can I be doing wrong?
Thanks


The map dashboard block defaults to New York because that is where Adafruit is located :)

Locational data (such as latitude, longitude and elevation) is sent to Adafruit IO as Metadata, included with a value.

A way to do this would be creating an additional feed named Location and sending it latitude and longitude values using the Adafruit IO API Create Data endpoint: https://io.adafruit.com/api/docs/?shell#create-data

If you're not using the Adafruit IO HTTP API - could you please post your code below in
Code: Select all | TOGGLE FULL SIZE
[code]code tags[/code]

brubell
 
Posts: 735
Joined: Fri Jul 17, 2015 10:33 pm

Re: Map not working

by pcborges on Mon Aug 19, 2019 4:55 pm

Hi, I am using ESP32 with code as below:
How do I send lat/long to the MAP block?
Thanks

Code: Select all | TOGGLE FULL SIZE
#include "WiFi.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include "DHTesp.h"
#define  DHTpin 4    //D4 of ESP32 DevKit
 
/************************* Conexão WiFi*********************************/
 
#define WIFI_SSID       "mynet" // nome de sua rede wifi
#define WIFI_PASS       "mypass"     // senha de sua rede wifi
 
/********************* Credenciais Adafruit io *************************/
 
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883   //secure=8883
#define AIO_USERNAME    "myusername" // Seu usuario cadastrado na plataforma da Adafruit
#define AIO_KEY         "mykey"       // Sua key da dashboard
 
/********************** Variaveis globais *******************************/
DHTesp     dht;
WiFiClient client;
 
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
 
int led01 = 2; // pino do led
 
//Adafruit_dhtTemp dhtTemp = Adafruit_dhtTemp(); // instancia o objeto do sensor
 
long previousMillis = 0;
bool saveAll=true;     //true=salva tudo, false=só quando mudar valor
 
/****************************** Declaração dos Feeds ***************************************/
 
/* feed responsavel por receber os dados da nossa dashboard */
Adafruit_MQTT_Subscribe _led01 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/led01", MQTT_QOS_1);
 
/* feed responsavel por enviar os dados do sensor para nossa dashboard */
Adafruit_MQTT_Publish _dhtTemp = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/dhtTemp", MQTT_QOS_1);
Adafruit_MQTT_Publish _dhtHum  = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/dhtHum",  MQTT_QOS_1);
/* Observe em ambas declarações acima a composição do tópico mqtt
  --> AIO_USERNAME "/feeds/dhtTemp"
  O dhtTemp será justamente o nome que foi dado la na nossa dashboard, portanto o mesmo nome atribuido la, terá de ser colocado aqui tambem
*/
 
/*************************** Declaração dos Prototypes ************************************/
 
void initSerial();
void initPins();
void initWiFi();
void initMQTT();
void initdht11();
void conectar_broker();
 
/*************************** Sketch ************************************/
 
void setup() {
  initSerial();
  initPins();
  initWiFi();
  initMQTT();
  initdht11();
}
 
void loop() {
  conectar_broker();
  mqtt.processPackets(5000);
  static float oldTemp=0,oldHum=0;
  bool mqttPostStatus;
 
  // Função responsável por ler e enviar o valor do sensor a cada 5 segundos
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > 5000 && mqtt.connected()) {
    previousMillis = currentMillis;
 
    float t = dht.getTemperature();
    float h = dht.getHumidity();
 
    if (oldTemp!=t || saveAll){
      Serial.print("Temp: "); Serial.print(t); Serial.println("°C");
      mqttPostStatus = _dhtTemp.publish(t);
      if (mqttPostStatus) {
        Serial.print("Falha ao enviar o temp do sensor: ");
        Serial.println(mqttPostStatus);
      }
      oldTemp=t;
    } else {
      Serial.println("Temp no change...");
    }

    if (oldHum!=h || saveAll){
      Serial.print("Humidade: "); Serial.print(h); Serial.println("%");
      mqttPostStatus = _dhtHum.publish(h);
      if (mqttPostStatus) {
        Serial.print("Falha ao enviar o hum do sensor: ");
        Serial.println(mqttPostStatus);
      }
      oldHum=h;
    } else {
      Serial.println("Humidity no change...");
    }
  }
}
 
/*************************** Implementação dos Prototypes ************************************/
 
/* Conexao Serial */
void initSerial() {
  Serial.begin(115200);
}
 
/* Configuração dos pinos */
void initPins() {
  pinMode(led01, OUTPUT);
  digitalWrite(led01, LOW);
}
 
/* Configuração da conexão WiFi */
void initWiFi() {
  Serial.print("Conectando-se na rede "); Serial.println(WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Conectado à rede com sucesso"); Serial.println("Endereço IP: "); Serial.println(WiFi.localIP());
}
 
/* Configuração da conexão MQTT */
void initMQTT() {
  _led01.setCallback(led01_callback);
  mqtt.subscribe(&_led01);
}
 
/* Inicialização do Sensor */
void initdht11() {
  dht.setup(DHTpin, DHTesp::DHT11); //for DHT11 Connect DHT sensor to GPIO 4 
}
 
/*************************** Implementação dos Callbacks ************************************/
 
/* callback responsavel por tratar o feed do led01 */
void led01_callback(char *data, uint16_t len) {
  String state = data;
  if (state == "ON") {
    digitalWrite(led01, HIGH);
  } else {
    digitalWrite(led01, LOW);
  }
  Serial.print("Led: "); Serial.println(state);
}
 
/*************************** Demais implementações ************************************/
 
/* Conexão com o broker e também servirá para reestabelecer a conexão caso caia */
void conectar_broker() {
  int8_t ret;
  uint8_t num_tentativas = 3;
   
  if (mqtt.connected()) {
    return;
  }
 
  Serial.println("Conectando-se ao broker mqtt...");
 
  while ((ret = mqtt.connect()) != 0) {
    Serial.println(mqtt.connectErrorString(ret));
    Serial.println("Falha ao se conectar. Tentando se reconectar em 5 segundos.");
    mqtt.disconnect();
    delay(5000);
    num_tentativas--;
    if (num_tentativas == 0) {
      Serial.println("Seu ESP será resetado.");
      while (1);
    }
  }
  Serial.println("Conectado ao broker com sucesso.");
}

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Re: Map not working

by brubell on Mon Aug 19, 2019 5:02 pm

If you switch to the Adafruit IO Arduino library, compatible with your ESP32, use the following example to send data to a feed named location.

https://github.com/adafruit/Adafruit_IO ... cation.ino

brubell
 
Posts: 735
Joined: Fri Jul 17, 2015 10:33 pm

Re: Map not working

by pcborges on Mon Aug 19, 2019 5:40 pm

Hi, I checked it.
I was trying to port adafruitio_15_temp_humidity.ino but it does not compile.
Removed all references to hardware I do not posses and included the DHT11 (DHTesp.h) I am currently using
Says error compiling to ESP32.

Isn't there a way just to add some code in this my Sketch that is already working?
Thanks

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Re: Map not working

by brubell on Mon Aug 19, 2019 5:51 pm

Could you please copy the error produced by the arduino ide and paste it here?

brubell
 
Posts: 735
Joined: Fri Jul 17, 2015 10:33 pm

Re: Map not working

by pcborges on Mon Aug 19, 2019 5:59 pm

OK:

exit status 1
Erro compilando para a placa ESP32 Dev Module

Code: Select all | TOGGLE FULL SIZE
// Adafruit IO temperatura & humidade Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-temperatura-and-humidade
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016-2017 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/
//#include <Adafruit_Sensor.h>
//#include <DHT.h>
//#include <DHT_U.h>

#include "DHTesp.h"
#define  DHTpin 4    //D4 of ESP32 DevKit

// pin connected to DH22 data line
//#define DATA_PIN 2

// create DHT22 instance
//DHT_Unified dht(DATA_PIN, DHT22);


// set up the 'temperatura' and 'humidade' feeds
AdafruitIO_Feed *temperatura = io.feed("temperatura");
AdafruitIO_Feed *humidade = io.feed("humidade");

void setup() {

  // start the serial connection
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);

  // initialize dht22
  //dht.begin();
  dht.setup(DHTpin, DHTesp::DHT11); //for DHT11 Connect DHT sensor to GPIO 4

  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();

  //sensors_event_t event;
  //dht.temperatura().getEvent(&event);

  //float celsius = event.temperatura;
  //float fahrenheit = (celsius * 1.8) + 32;

  float celsius = dht.getTemperature();
  float fahrenheit = (celsius * 1.8) + 32;

  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");

  Serial.print("fahrenheit: ");
  Serial.print(fahrenheit);
  Serial.println("F");

  // save fahrenheit (or ) to Adafruit IO
  temperatura->save(celsius);

  //dht.humidade().getEvent(&event);
  float humidade = dht.getHumidity();

  Serial.print("humidade: ");
  Serial.print(humidade);
  Serial.println("%");

  // save humidade to Adafruit IO
  humidade->save(humidade);

  // wait 5 seconds (5000 milliseconds == 5 seconds)
  delay(5000);

}



config.h
Code: Select all | TOGGLE FULL SIZE
/************************ Adafruit IO Config *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883   //secure=8883
#define AIO_USERNAME    "myuser" // Seu usuario cadastrado na plataforma da Adafruit
#define AIO_KEY         "mykey"       // Sua key da dashboard

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
//   - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
//   - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
//   - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
//   - Feather M0 WiFi -> https://www.adafruit.com/products/3010
//   - Feather WICED -> https://www.adafruit.com/products/3056
//   - Adafruit PyPortal -> https://www.adafruit.com/product/4116
//   - Adafruit Metro M4 Express AirLift Lite -> https://www.adafruit.com/product/4000
//   - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
//   - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
//   - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264

#define WIFI_SSID   "myuser"
#define WIFI_PASS   "mypass"

// uncomment the following line if you are using airlift
// #define USE_AIRLIFT

// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

//#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
  // Configure the pins used for the ESP32 connection
  //#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
    // Don't change the names of these #define's! they match the variant ones
  //  #define SPIWIFI SPI
  //  #define SPIWIFI_SS 10  // Chip select pin
  //  #define NINA_ACK 9    // a.k.a BUSY or READY pin
 //   #define NINA_RESETN 6 // Reset pin
 //   #define NINA_GPIO0 -1 // Not connected
 // #endif
 // AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
//#else
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
//#endif
/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);

/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Re: Map not working

by pcborges on Mon Aug 19, 2019 8:49 pm

Hi again.

I found that it is not compiling due to the following error:

C:\Users\pctbo\OneDrive\Documents\Arduino\libraries\Adafruit_IO_Arduino-master\src/AdafruitIO.h:23:31: fatal error: ArduinoHttpClient.h: No such file or directory
compilation terminated.

ESP32 uses HTTPClient.h

How can I solve this problem?
Thanks

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Re: Map not working

by brubell on Tue Aug 20, 2019 11:08 am

Navigate to the Manage Libraries... option in the Sketch -> Include Library menu.

Then, enter ArduinoHttpClient into the search box, and click Install on the ArduinoHttpClient library option to install version 0.2.0 or higher.

brubell
 
Posts: 735
Joined: Fri Jul 17, 2015 10:33 pm

Re: Map not working

by pcborges on Tue Aug 20, 2019 8:07 pm

Hi, thanks for your support.

I did the update as per your instruction, Now the compiler stops at:
C:\Users\pctbo\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32/Client.h:32:17: note: virtual int Client::connect(const char*, uint16_t, int)

virtual int connect(const char *host, uint16_t port, int timeout) =0;

Again with Error compiling for the board ESP32 Dev Module.

Thanks
Paulo

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Re: Map not working

by brubell on Thu Aug 22, 2019 9:58 am

Could you try downgrading the ESP32's firmware?

Instructions to do this are found on the following thread:
viewtopic.php?f=56&t=152781

brubell
 
Posts: 735
Joined: Fri Jul 17, 2015 10:33 pm

Re: Map not working

by pcborges on Thu Aug 22, 2019 1:15 pm

Dear brubell, thanks for the support, now it compiles ok.
Back to the map problem.

I did find the following sample code:
Code: Select all | TOGGLE FULL SIZE
AdafruitIO_Feed *gpslatlng = io.feed("gpslatlng");


and then inside loop:

Code: Select all | TOGGLE FULL SIZE
  float GPSlat = (-22.893552);        // variable to store latitude
  float GPSlng = (-42.820837);        // variable to store longitude
  float GPSalt = (3);                 // variable to store altitude

  char gpsbuffer[30];                         // Combine Latitude, Longitude, Altitude into a buffer of size X
  char *p = gpsbuffer;                        // Create a buffer to store GPS information to upload to Adafruit IO                       </p><p>            dtostrf(Distance_To_Home, 3, 4, p);         // Convert Distance to Home to a String Variable and add it to the buffer
  p += strlen(p);
  //p[0] = ','; p++;                     
           
  dtostrf(GPSlat, 3, 6, p);                   // Convert GPSlat(latitude) to a String variable and add it to the buffer
  p += strlen(p);
  p[0] = ','; p++;
                                                           
  dtostrf(GPSlng, 3, 6, p);                   // Convert GPSlng(longitude) to a String variable and add it to the buffer
  p += strlen(p);
  p[0] = ','; p++; 
                                                           
  dtostrf(GPSalt, 2, 1, p);                   // Convert GPSalt(altimeter) to a String variable and add it to the buffer
  p += strlen(p);

  gpslatlng->save(gpsbuffer);   


It is likely wrong and the map is blank.
The link you sent previously does not seem to match my way of coding.

Thanks in advance.

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Re: Map not working

by pcborges on Thu Aug 22, 2019 1:59 pm

Hi again.
Sorted out...
I was looking into the wrong tab on the link you passed "https://io.adafruit.com/api/docs/?cpp#create-data"
Now looking into the Arduino tab I got the right code.
Thanks
Works great.

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Re: Map not working

by pcborges on Thu Aug 22, 2019 2:09 pm

Now, to complement:
In my old code I had a button to send "ON" or "OFF" to control a LED on my ESP32
For that I had a subscribe:

Code: Select all | TOGGLE FULL SIZE
Adafruit_MQTT_Subscribe _led01 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/led01", MQTT_QOS_1);


and...

Code: Select all | TOGGLE FULL SIZE
  _led01.setCallback(led01_callback);
  mqtt.subscribe(&_led01);


How do I subscribe in this new scenario?
Thanks in advance
Paulo

pcborges
 
Posts: 10
Joined: Thu Aug 15, 2019 6:18 am

Please be positive and constructive with your questions and comments.