简体   繁体   中英

Arduino Uno or php

I'm want to grab geolocation coordinates using Google Maps API, send it to my Arduino Uno, and parse the message into a floating numbers array.

I have used strok() with , as the delimiter but I'm having trouble parsing the SMS message with text and brackets.

Sent from your Twilio trial account - (43.39114023431447, -80.40987968444824)(43.387210701009224, -80.41219711303711)(43.38602555366178, -80.38970947265625)

I just need to parse the coordinates into a float array.

I resolved it on my own using strok() function

{
     const char *delim  = "(";   //a '(' is the delimiter
     const char *delim1  = ",";
     const char *delim3  = ")";
     char *text;
     char *firstItem;
     char *secondItem;
     char *thirdItem;
     char *fourthItem;
     char *fivethItem;
     char *sixthItem;
     char *seventhItem;
     char *eighthItem;
     text = strtok(password,delim);
     firstItem = strtok(NULL,delim1);
     secondItem = strtok(NULL,delim3);
     secondItem++;
     thirdItem = strtok(NULL,delim1);
     thirdItem++;
     fourthItem = strtok(NULL,delim3);
     fourthItem++;
     fivethItem = strtok(NULL,delim1);
     fivethItem++;
     sixthItem = strtok(NULL,delim3);
     sixthItem++;
     polyX[0] = atof(firstItem);
     polyY[0] = atof(secondItem);
     polyX[1] = atof(thirdItem);
     polyY[1] = atof(fourthItem);
     polyX[2] = atof(fivethItem);
     polyY[2] = atof(sixthItem);
     memset (password,NULL,sizeof(password));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM