Page 1 of 1

We are tryng to make a gps tracker using the gps module NEO-6M and the particle argon board. We will be using the partic

Posted: Fri May 20, 2022 4:29 pm
by answerhappygod
We are tryng to make a gps tracker using the gps module NEO-6M and the particle argon board. We will be using the particle web IDE platform to upload the code to the argon board.
We want the location to be uploaded to a twitter account every minute using the ibm red node app
here is the code:
// This #include statement was automatically added by the Particle IDE.
#include <MQTT.h> //search and include the mqtt library via Particle online IDE
#define HOST_PORT 1883 //port# used by host (IBM Watson IoT Platform): 1883 (default)
//change part# to 443 for secure connection
#define MQTT_QoS 0 //MQTT QoS = 0: message will be delivered zero or once (default)
//MQTT QoS = 1: message will be delivered at least once
//MQTT QoS = 2: message will be delivered exactly once
//Use your device information to fill in the following code in line17~21
char *MQTT_HOST = "b692c9.messaging.internetofthings.ibmcloud.com";
char *MQTT_CLIENT = "d:b692c9:Korgon6:KorgonFTL";
//an example of MQTT_CLIENT is "d:myorgID:photons:photon_a1";
char *MQTT_USERNAME = "use-token-auth";
char *MQTT_PASSWORD = "+ERZRjV4InncH6Bq6&";
// MQTT Message Topic of the data that will be sent to Watson.
// iot-2 --> The protocol
// evt --> Specifies the message type, use "cmd" for applications
// testdata --> Name of message //it is also Event's name. Important! Needed by cloud!
// fmt/json --> Message will be send in JSON format // Watson use JSON format as default!
char *EVENT_TOPIC = "iot-2/evt/KorgonD/fmt/json"; // Segment can be customized by you
MQTT client( MQTT_HOST, HOST_PORT, callback ); //Create a MQTT client for your device
int KorgonD = 0;
int potentiometer = A0;
int IndicatorLed = D0;
char payload[80]; //MQTT message's payload. A string in JASON format.
// 80Bytes used here. Change the size according to your data.
void setup() {
pinMode(IndicatorLed, OUTPUT);
RGB.control(true);
Serial.begin( 9600 ); //Use serial monitor to debug the code.
//Read “Particle serial tutorial” for detailed how-to.
Serial.println( "Connecting Photon to IBM Watson IoT Platform ...... " );
while( !Serial.available() ) {
Particle.process();
}
client.connect(MQTT_CLIENT,MQTT_USERNAME,MQTT_PASSWORD);//Connect Photon to Watson IoT Platform
if( client.isConnected() ) { //Verify the connection
Serial.println( "Now connected!" );
// client.subscribe( MQTT_SUBSCRIBE ); //This sample code is only to send data to cloud,
//not subscribe from cloud, so this line is commented out.
}
}
void loop() {
KorgonD ++;
KorgonD = analogRead(potentiometer);
if (KorgonD>500) KorgonD = 0;
//Convert data to a JSON format string on line66:
//JSON format example: {“property”: value1, ”property2”: value2,...}
sprintf(payload, "{ \"KorgonDataProperty\": \"%d\" }", KorgonD);
//send the JSON formatted payload (including the data) to Watson under the pre-defined topic
client.publish(EVENT_TOPIC, const_cast<char*> (payload) );
digitalWrite(IndicatorLed, HIGH); //Quickly blink the LED D7 once when a data is sent
delay(100);
digitalWrite(IndicatorLed, LOW);
delay(100);
client.loop();
Serial.print( "Data being sent to Cloud: " ); //Display the sent data on SerialMonitor
Serial.println(KorgonD);
delay( 5000 ); //Set the period of sending data
}
void callback( char* topic, byte* payload, unsigned int length ) {
char p[length+1];
memcpy( p, payload, length );
p[length] = NULL;
String message( p );
}
based on the example code that I have given here, can you please create and edit it as a gps tracker on particle IDE web program so we can upload and connect the code to our argon board.