Stap 5: MQTT abonnement en Item aankoop met behulp van de robotarm
Na de selectie, zal de app een MQTT-mailbericht publiceren, klanten hebben de optie om te selecteren van de items die met behulp van de Android App en het zal worden ingeschreven in edison. Wanneer edison krijgt de productinformatie, het zal naar de producten en de RFID, het zal vast te stellen welke het product en wanneer het identificeert, de robot zal er stoppen en vervolgens de robotarm halen van het item en zet het in de kar.
if (res == 'a') { // Getting the product id 'a' from the Android App using MQTT. i.e. Customer selected the Items to purchase through App rfidon(); // Call the function for Tracking the product using RFID motor1.run(FORWARD); // Trolley is moving to find the item } // Function rfidon()<br><br>void rfidon()</p><p>{ Serial.println("RFID is working Now"); uchar i, tmp; uchar status; uchar str[MAX_LEN]; uchar RC_size; uchar blockAddr; //选择操作的块地址0~63 String mynum = ""; //runFunction(); //寻卡,返回卡类型 status = MFRC522_Request(PICC_REQIDL, str); Serial.println(status); Serial.println(MI_OK); while (status != MI_OK) { status = MFRC522_Request(PICC_REQIDL, str); Serial.println(status); Serial.println(MI_OK); if (status == MI_OK) { Serial.println("Card detected"); status = MFRC522_Anticoll(str); memcpy(serNum, str, 5); if (status == MI_OK) { do{ Serial.println("The card's number is : "); Serial.print(serNum[0]); Serial.print(" , "); Serial.print(serNum[1], BIN); Serial.print(" , "); Serial.print(serNum[2], BIN); Serial.print(" , "); Serial.print(serNum[3], BIN); Serial.print(" , "); Serial.print(serNum[4], BIN); status = MFRC522_Request(PICC_REQIDL, str); status = MFRC522_Anticoll(str); memcpy(serNum, str, 5); //Serial.println(" "); // Should really check all pairs, but for now we'll just use the first } while (serNum[0] != 225); if (serNum[0] == 225) { Serial.println("RFID Detected"); // Product is Identified Serial.print(serNum[0]); MotorSpeedSetAB(0,0); // Stopping the Vehicle / Trolley servo_4.attach(9); for(servo4_pos =175; servo4_pos >= 30; servo4_pos--) { servo_4.write(servo4_pos); delay(20); //Serial.println("inside servo 4 "); } servo_4.detach(); delay(1000); servo_1.attach(3); for(servo1_pos =5; servo1_pos <= 100; servo1_pos++) { servo_1.write(servo1_pos); delay(20); } servo_1.detach(); delay(1000);</p><p> delay(1000); servo_1.attach(3); for(servo1_pos =100; servo1_pos >= 5; servo1_pos--) { servo_1.write(servo1_pos); delay(20); } delay(1000);</p><p> servo_4.attach(9); for(servo4_pos =30; servo4_pos <= 175; servo4_pos++) { servo_4.write(servo4_pos); delay(20); Serial.println("inside servo 4 "); } servo_4.detach(); //break; delay(1000); servo_1.attach(3); for(servo1_pos =5; servo1_pos <= 100; servo1_pos++) { servo_1.write(servo1_pos); delay(20); } for(servo1_pos =100; servo1_pos >= 5; servo1_pos--) { servo_1.write(servo1_pos); delay(20); } servo_1.detach(); delay(1000); } } // Serial.print(str[0],BIN); // Serial.print(" , "); // Serial.print(str[1],BIN); // Serial.println(" "); } } //Serial.println(" "); MFRC522_Halt();