Trouble using popen() on a pi3

I have a simple program to get data from a python script and publish it. when I call a simple python script (print(‘Hello’)) everything works fine. But the script I want to call has a delay of 10 seconds (scanning bluetooth LE sensors) before it returns a string. If I run the same code on the Pi itself it waits the 10 seconds and then prints the data. But the Particle code doesn’t wait and returns no data.

Having some code to look at would definitely help :wink:

1 Like

Not much to it:

#include <stdio.h>

char c[20];
FILE *pyin;

void setup() {
    Serial.begin(9600);
}

void loop() {
    if (Time.second() == 0){
        getTemp();
        Particle.publish("outside",c,60,PRIVATE);
        delay(1000);
    }
}

void getTemp(){
    pyin = popen("/root/python/particle_test.py","r");
	fscanf(pyin,"%[^\n]",c);
	Serial.printlnf("Data from Python: %s",c);
	pclose(pyin);
}

Thanks peekay123

The fix proved to be simple, added a ‘delay(x)’ between the popen a fscanf lines.