How to convert published string data to an int after subscribed to

Hi everyone, I’m not that good when it comes to dealing with strings so if this is an easy question then you understand. Anyways I have a code to subscribe to a potentiometer value which is converted into a string before it’s published which is on Photon A. Now Photon B subscribes to that. But the trouble is I need to know how to convert a string to an int after subscribing to an event so that way when I try to send that data to my arduino via tx the data isn’t bogus. Here is my code that subscribes:

int reading1;
String reading1AsAString;

void setup() {
Particle.subscribe(“sense1”, myHandler);

void loop() {
void myHandler(const char *eventname, const char *data) {



So the ‘data’ is in a string. I would like to know how to convert that string to an int before the line " Serial1.println(data);" Sorry if this is unclear (I’m new to the particle community). If you need to see the publishing code just ask, or if you want me to clarify. -Thanks :grinning:

try aoti()

void myHandler(const char *eventname, const char *data) 
  int myValue = atoi(data);
1 Like

Thanks @BulldogLowell your suggestion works great!