I’m having problems with Tracker One, trying to obtain Latitude and Longitude using Custom Function instead of Default Function using: {“cmd”:“get_loc”}
I can’t find in Documents how to read the current position and turn it into a Variable.
Here is a sample of my code:
float Longitude;
float Latitude;
void setup()
{
Particle.function("controlPanel", controlPanel);
}
void loop()
{
// How do I get longitude and latitude from Tracker One
// and pass it to my Function below?
}
int controlPanel(String command)
{
if (command == "longitude")
{
Particle.publish("Longitude is:", Longitude, PRIVATE);
}
if (command == "latitude")
{
Particle.publish("Latitude is:", Latitude, PRIVATE);
}
return true;
}
Thank you
You can’t start with empty firmware, because none of the Tracker features will exist. You need to start with the Tracker Edge Firmware and then add in your custom code.
Once you have the Tracker Edge firmware, you add your function handler registration to setup() and the code to implement it. The getLocation() function is what you need to get the current location.
Okay, I got the Tracker Edge Firmware on my Workbench, I was able to flash with the following code and my Function controlPanel is not showing up. It’s not accepting any custom code at this moment.
// INCLUDE
#include "tracker.h"
// EXAMPLE
#include "Particle.h"
#include "tracker_config.h"
#include "tracker.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
PRODUCT_ID(PLATFORM_ID);
PRODUCT_VERSION(1);
SerialLogHandler logHandler(115200, LOG_LEVEL_TRACE, {
{"app.gps.nmea", LOG_LEVEL_INFO},
{"app.gps.ubx", LOG_LEVEL_INFO},
{"ncp.at", LOG_LEVEL_INFO},
{"net.ppp.client", LOG_LEVEL_INFO},
});
int controlPanel(String command);
void setup()
{
Particle.function("controlPanel", controlPanel);
Tracker::instance().init();
Particle.connect();
}
void loop()
{
Tracker::instance().loop();
}
// Cloud Function
int controlPanel(String command)
{
if (command == "test")
{
Particle.publish("FUNCTION", "IS WORKING", PRIVATE);
}
return 1;
}
What am I doing wrong?
In the console, go into the product that was created when you set up your Tracker (every Tracker must be in a product), click on the Devices icon, then make sure the device is marked as a Developer Device.
Otherwise, as soon as the device comes online, it will be reverted to the factory Tracker Edge firmware.
It’s been selected as Development Device since I started working on it.
I got it to work, files were mixed up, thank you