aoabook / Arduino

This is all the Arduino code for the book in a single repository, unlike the Java code, the Arduino one is very compact, and it would make little sense to separate it in different repositories. It also includes the libraries used for the projects.
12 stars 20 forks source link

Having problems in P2PMQTT.h #3

Open YushaBinArif opened 6 years ago

YushaBinArif commented 6 years ago

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

Wrox_AOA_c8p1_Basic_Robot:52: error: 'P2PMQTT' does not name a type

P2PMQTT mqtt(true); // add parameter true for debugging

^

E:\arduino-1.8.5\libraries\AOA_code\Wrox_AOA_c8p1_Basic_Robot\Wrox_AOA_c8p1_Basic_Robot.ino: In function 'void setup()':

Wrox_AOA_c8p1_Basic_Robot:60: error: 'mqtt' was not declared in this scope

mqtt.begin("Basic Robot");

^

E:\arduino-1.8.5\libraries\AOA_code\Wrox_AOA_c8p1_Basic_Robot\Wrox_AOA_c8p1_Basic_Robot.ino: In function 'void loop()':

Wrox_AOA_c8p1_Basic_Robot:70: error: 'mqtt' was not declared in this scope

int type = mqtt.getType(mqtt.buffer);

          ^

Wrox_AOA_c8p1_Basic_Robot:75: error: 'CONNECT' was not declared in this scope

 case CONNECT:

      ^

Wrox_AOA_c8p1_Basic_Robot:79: error: 'PUBLISH' was not declared in this scope

 case PUBLISH:

      ^

exit status 1 'P2PMQTT' does not name a type

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

/// These are the errors i am having while importing P2PMQTT.h in my arduino code

agoransson commented 6 years ago

Can you include your sketch please?

YushaBinArif commented 6 years ago

Yes here it is

/// sketch

include

include

int payload = -1; P2PMQTT mqtt(true); // add parameter true for debugging void setup() { // use the serial port to monitor that things work Serial.begin(9600); Serial.println("ready"); mqtt.connect(0,60000); // add 1min timeout

// initiate the communication to the phone
mqtt.begin("Basic Robot"); } // to store the data

void loop() { // get a P2PMQTT package and extract the type
int type = mqtt.getType(mqtt.buffer); // depending on the package type do different things switch(type) { case CONNECT: Serial.println("connected"); break;
case PUBLISH: payload = mqtt.getPayload(mqtt.buffer, type)[0]; Serial.print("command: "); Serial.println(payload);
break; default: // do nothing break; } }

YushaBinArif commented 6 years ago

I first unzipped the files in "libraries" directory where all the default libraries of arduino are present, then wrote the above code.