The main objective is to reduce loss in revenue due to delayed shelf-restocking (when product is in-stock in the store but not stocked on the shelf) and inaccurate forecasting (under-estimating future product sales) practices. The result is to demonstrate inventory automation using ECIS system by enabling the means to monitor and track store inventory in real-time, perform data analysis remotely in cloud, improve shopping experience for the consumers and increase revenue for the retailers in the retail industry. Machine Learning code can be found on my GitHub: https://github.com/priyankkalgaonkar
ECE 53301: Wireless and Multimedia Computing Final Project Report – Group 1
Inventory Automation Using Electronically Connected Intelligent Shelves.
Code Developed by: Priyank Kalgaonkar.
Department of Electrical and Computer Engineering, Purdue School of Engineering and Technology at IUPUI.
Submitted as partial fulfillment for the requirement of Fall 2019 - ECE 53301-26877: Wireless and Multimedia Computing course.
Date of Submission: December 12, 2019.
FinalVersionECISsystem/main.cpp@0:b0c4c25d37ab, 2019-12-12 (annotated)
- Committer:
- priyank12p
- Date:
- Thu Dec 12 01:04:52 2019 +0000
- Revision:
- 0:b0c4c25d37ab
- Child:
- 1:45dc700211a7
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
priyank12p | 0:b0c4c25d37ab | 1 | /** |
priyank12p | 0:b0c4c25d37ab | 2 | Group 1: Electronically Controlled Intelligent Shelves |
priyank12p | 0:b0c4c25d37ab | 3 | Developed by: Priyank Kalgaonkar |
priyank12p | 0:b0c4c25d37ab | 4 | ECE53301 - Final Project - Fall 2019 |
priyank12p | 0:b0c4c25d37ab | 5 | **/ |
priyank12p | 0:b0c4c25d37ab | 6 | |
priyank12p | 0:b0c4c25d37ab | 7 | #include "mbed.h" |
priyank12p | 0:b0c4c25d37ab | 8 | #include "hcsr04.h" |
priyank12p | 0:b0c4c25d37ab | 9 | #include "ESP8266.h" |
priyank12p | 0:b0c4c25d37ab | 10 | #include "math.h" |
priyank12p | 0:b0c4c25d37ab | 11 | #define CloudIP "184.106.153.149" //Raw IP Address of ThingSpeak Cloud Server |
priyank12p | 0:b0c4c25d37ab | 12 | |
priyank12p | 0:b0c4c25d37ab | 13 | DigitalOut RLed(LED1); //Onboard Red LED = Shelf Out of Stock |
priyank12p | 0:b0c4c25d37ab | 14 | DigitalOut GLed(LED2); //Onboard Green LED = All OK |
priyank12p | 0:b0c4c25d37ab | 15 | DigitalOut BLed(LED3); //Onboard Blue LED for Wifi Tx Indication |
priyank12p | 0:b0c4c25d37ab | 16 | HCSR04 usensor1(D8,D9); //ECHO Pin=D9, TRIG Pin=D8 |
priyank12p | 0:b0c4c25d37ab | 17 | HCSR04 usensor2(D7,D6); //ECHO Pin=D7, TRIG Pin=D6 |
priyank12p | 0:b0c4c25d37ab | 18 | Serial pc(USBTX,USBRX); //Serial Communication with PC |
priyank12p | 0:b0c4c25d37ab | 19 | ESP8266 wifi(PTC17, PTC16, 115200); //Tx Pin:PTC17; Rx Pin:PTC17; Baud rate:115200 |
priyank12p | 0:b0c4c25d37ab | 20 | |
priyank12p | 0:b0c4c25d37ab | 21 | void wifi_send(void);; //Connect and Push Data Channel to Cloud Server |
priyank12p | 0:b0c4c25d37ab | 22 | |
priyank12p | 0:b0c4c25d37ab | 23 | int num = 0; |
priyank12p | 0:b0c4c25d37ab | 24 | int distance1, distance2; |
priyank12p | 0:b0c4c25d37ab | 25 | float dist_remaining1, dist_percent1, dist_remaining2, dist_percent2; |
priyank12p | 0:b0c4c25d37ab | 26 | char snd[255],rcv[1000]; //snd: send command to ESP8266 |
priyank12p | 0:b0c4c25d37ab | 27 | //rcv: receive response from ESP8266 |
priyank12p | 0:b0c4c25d37ab | 28 | |
priyank12p | 0:b0c4c25d37ab | 29 | int main() |
priyank12p | 0:b0c4c25d37ab | 30 | { |
priyank12p | 0:b0c4c25d37ab | 31 | pc.baud(115200); //Baud Rate of 115200 for Tera Term |
priyank12p | 0:b0c4c25d37ab | 32 | |
priyank12p | 0:b0c4c25d37ab | 33 | pc.printf("######## ###### #### ###### ###### ## ## ###### ######## ######## ## ##\n\r"); |
priyank12p | 0:b0c4c25d37ab | 34 | pc.printf("## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ###\n\r"); |
priyank12p | 0:b0c4c25d37ab | 35 | pc.printf("## ## ## ## ## #### ## ## ## #### ####\n\r"); |
priyank12p | 0:b0c4c25d37ab | 36 | pc.printf("###### ## ## ###### ###### ## ###### ## ###### ## ### ##\n\r"); |
priyank12p | 0:b0c4c25d37ab | 37 | pc.printf("## ## ## ## ## ## ## ## ## ## ##\n\r"); |
priyank12p | 0:b0c4c25d37ab | 38 | pc.printf("## ## ## ## ## ## ## ## ## ## ## ## ## ## ##\n\r"); |
priyank12p | 0:b0c4c25d37ab | 39 | pc.printf("######## ###### #### ###### ###### ## ###### ## ######## ## ##\n\r"); |
priyank12p | 0:b0c4c25d37ab | 40 | pc.printf("-----------------------------------------------------------------------------------------\n\r"); |
priyank12p | 0:b0c4c25d37ab | 41 | pc.printf("Project By: Priyank Kalgaonkar, Sahil Kumar, Linknath Surya Balasubramanian\n\r"); |
priyank12p | 0:b0c4c25d37ab | 42 | pc.printf("-----------------------------------------------------------------------------------------\n\r\n\r"); |
priyank12p | 0:b0c4c25d37ab | 43 | |
priyank12p | 0:b0c4c25d37ab | 44 | pc.printf("Initial Setup\r\n"); |
priyank12p | 0:b0c4c25d37ab | 45 | wifi.SetMode(1); //Set ESP mode to 1 |
priyank12p | 0:b0c4c25d37ab | 46 | wifi.RcvReply(rcv, 1000); //Receive a response from ESP |
priyank12p | 0:b0c4c25d37ab | 47 | pc.printf("%s\r", rcv); |
priyank12p | 0:b0c4c25d37ab | 48 | |
priyank12p | 0:b0c4c25d37ab | 49 | pc.printf("Conneting to WiFi\r\n"); //AP Setup Initialization |
priyank12p | 0:b0c4c25d37ab | 50 | wifi.Join("Priyank's iPhone", "audi1155"); |
priyank12p | 0:b0c4c25d37ab | 51 | wifi.RcvReply(rcv, 1000); |
priyank12p | 0:b0c4c25d37ab | 52 | pc.printf("%s\n", rcv); |
priyank12p | 0:b0c4c25d37ab | 53 | wait(8); |
priyank12p | 0:b0c4c25d37ab | 54 | |
priyank12p | 0:b0c4c25d37ab | 55 | wifi.GetIP(rcv); //Obtains an IP address from the AP |
priyank12p | 0:b0c4c25d37ab | 56 | |
priyank12p | 0:b0c4c25d37ab | 57 | while (1) |
priyank12p | 0:b0c4c25d37ab | 58 | { |
priyank12p | 0:b0c4c25d37ab | 59 | wifi_send(); |
priyank12p | 0:b0c4c25d37ab | 60 | |
priyank12p | 0:b0c4c25d37ab | 61 | RLed = 1; |
priyank12p | 0:b0c4c25d37ab | 62 | GLed = 1; |
priyank12p | 0:b0c4c25d37ab | 63 | BLed = 0; |
priyank12p | 0:b0c4c25d37ab | 64 | wait(2.0f); |
priyank12p | 0:b0c4c25d37ab | 65 | } |
priyank12p | 0:b0c4c25d37ab | 66 | } |
priyank12p | 0:b0c4c25d37ab | 67 | |
priyank12p | 0:b0c4c25d37ab | 68 | void wifi_send(void) |
priyank12p | 0:b0c4c25d37ab | 69 | { |
priyank12p | 0:b0c4c25d37ab | 70 | while(num<1000000000000) |
priyank12p | 0:b0c4c25d37ab | 71 | { |
priyank12p | 0:b0c4c25d37ab | 72 | num=num+1; |
priyank12p | 0:b0c4c25d37ab | 73 | pc.printf("Cloud Sync Instance #: %d\n\r", num); |
priyank12p | 0:b0c4c25d37ab | 74 | pc.printf("Syncing Data with Cloud, Please Wait.\n\r"); |
priyank12p | 0:b0c4c25d37ab | 75 | |
priyank12p | 0:b0c4c25d37ab | 76 | //Ultrasound Sensor (HC-SR04) #1 Initialization |
priyank12p | 0:b0c4c25d37ab | 77 | int a = 30; |
priyank12p | 0:b0c4c25d37ab | 78 | usensor1.start(); |
priyank12p | 0:b0c4c25d37ab | 79 | wait_ms(500); |
priyank12p | 0:b0c4c25d37ab | 80 | |
priyank12p | 0:b0c4c25d37ab | 81 | //Calculating Distance Percentage Remaining for Sensor # 1 |
priyank12p | 0:b0c4c25d37ab | 82 | distance1 = usensor1.get_dist_cm(); |
priyank12p | 0:b0c4c25d37ab | 83 | dist_remaining1 = a-distance1; |
priyank12p | 0:b0c4c25d37ab | 84 | dist_percent1 = (dist_remaining1/30)*100; |
priyank12p | 0:b0c4c25d37ab | 85 | |
priyank12p | 0:b0c4c25d37ab | 86 | //Ultrasound Sensor (HC-SR04) #2 Initialization |
priyank12p | 0:b0c4c25d37ab | 87 | int b = 30; |
priyank12p | 0:b0c4c25d37ab | 88 | usensor2.start(); |
priyank12p | 0:b0c4c25d37ab | 89 | wait_ms(500); |
priyank12p | 0:b0c4c25d37ab | 90 | |
priyank12p | 0:b0c4c25d37ab | 91 | //Calculating Distance Percentage Remaining for Sensor # 2 |
priyank12p | 0:b0c4c25d37ab | 92 | distance2 = usensor2.get_dist_cm(); |
priyank12p | 0:b0c4c25d37ab | 93 | dist_remaining2 = b-distance2; |
priyank12p | 0:b0c4c25d37ab | 94 | dist_percent2 = (dist_remaining2/30)*100; |
priyank12p | 0:b0c4c25d37ab | 95 | |
priyank12p | 0:b0c4c25d37ab | 96 | //LED and Tera Term Output |
priyank12p | 0:b0c4c25d37ab | 97 | if (distance1<30 && distance2<30) { |
priyank12p | 0:b0c4c25d37ab | 98 | RLed = 1; |
priyank12p | 0:b0c4c25d37ab | 99 | BLed = 1; |
priyank12p | 0:b0c4c25d37ab | 100 | GLed = 0; |
priyank12p | 0:b0c4c25d37ab | 101 | //printf("Percent remaining: %f\r", dist_percent1 && dist_percent2); |
priyank12p | 0:b0c4c25d37ab | 102 | } else { |
priyank12p | 0:b0c4c25d37ab | 103 | GLed = 1; |
priyank12p | 0:b0c4c25d37ab | 104 | BLed = 1; |
priyank12p | 0:b0c4c25d37ab | 105 | RLed = 0; |
priyank12p | 0:b0c4c25d37ab | 106 | printf("Shelves Empty! Replenish Stock.\n\r"); |
priyank12p | 0:b0c4c25d37ab | 107 | } |
priyank12p | 0:b0c4c25d37ab | 108 | |
priyank12p | 0:b0c4c25d37ab | 109 | //Sending Data to the Cloud Server via ESP8266 WiFi Module |
priyank12p | 0:b0c4c25d37ab | 110 | strcpy(snd,"AT+CIPMUX=0\n\r"); //AT+CIPMUX: Enabling Single Channel Mode |
priyank12p | 0:b0c4c25d37ab | 111 | wifi.SendCMD(snd); |
priyank12p | 0:b0c4c25d37ab | 112 | wait(1); |
priyank12p | 0:b0c4c25d37ab | 113 | wifi.RcvReply(rcv, 1000); |
priyank12p | 0:b0c4c25d37ab | 114 | wait(1); |
priyank12p | 0:b0c4c25d37ab | 115 | |
priyank12p | 0:b0c4c25d37ab | 116 | sprintf(snd,"AT+CIPSTART=4,\"TCP\",\"%s\",80\n",CloudIP); //Establish TCP connection w/ Cloud Server |
priyank12p | 0:b0c4c25d37ab | 117 | wait(1); |
priyank12p | 0:b0c4c25d37ab | 118 | wifi.RcvReply(rcv, 1000); |
priyank12p | 0:b0c4c25d37ab | 119 | wait(1); |
priyank12p | 0:b0c4c25d37ab | 120 | |
priyank12p | 0:b0c4c25d37ab | 121 | strcpy(snd,"AT+CIPSEND=100\n\r"); //Set length of the data that will be sent |
priyank12p | 0:b0c4c25d37ab | 122 | wifi.SendCMD(snd); |
priyank12p | 0:b0c4c25d37ab | 123 | pc.printf("%s\r", rcv); |
priyank12p | 0:b0c4c25d37ab | 124 | wait(1); |
priyank12p | 0:b0c4c25d37ab | 125 | wifi.RcvReply(rcv, 1000); |
priyank12p | 0:b0c4c25d37ab | 126 | pc.printf("%s\r", rcv); |
priyank12p | 0:b0c4c25d37ab | 127 | wait(1); |
priyank12p | 0:b0c4c25d37ab | 128 | |
priyank12p | 0:b0c4c25d37ab | 129 | //Pushing the data acquired from HC-SR04 Ultrasonic Sensor to Cloud Server via API |
priyank12p | 0:b0c4c25d37ab | 130 | //pc.printf("Product X - Sensor 1: "); |
priyank12p | 0:b0c4c25d37ab | 131 | sprintf(snd,"GET https://api.thingspeak.com/update?api_key=O59NSRSQZCJ2G6WK&field1=%f\r", dist_percent1); |
priyank12p | 0:b0c4c25d37ab | 132 | printf("Product X: Percent Stock Remaining: %f\n\r", dist_percent1); |
priyank12p | 0:b0c4c25d37ab | 133 | wifi.SendCMD(snd); |
priyank12p | 0:b0c4c25d37ab | 134 | //pc.printf("%s\r",snd); |
priyank12p | 0:b0c4c25d37ab | 135 | wait(1); |
priyank12p | 0:b0c4c25d37ab | 136 | wifi.RcvReply(rcv, 1000); |
priyank12p | 0:b0c4c25d37ab | 137 | pc.printf("%s\r", rcv); |
priyank12p | 0:b0c4c25d37ab | 138 | |
priyank12p | 0:b0c4c25d37ab | 139 | //pc.printf("Product Y - Sensor 2: "); |
priyank12p | 0:b0c4c25d37ab | 140 | sprintf(snd,"GET https://api.thingspeak.com/update?api_key=O59NSRSQZCJ2G6WK&field2=%f\n\r\n\r", dist_percent2); |
priyank12p | 0:b0c4c25d37ab | 141 | wifi.SendCMD(snd); |
priyank12p | 0:b0c4c25d37ab | 142 | //pc.printf("%s\r",snd); |
priyank12p | 0:b0c4c25d37ab | 143 | printf("Product Y: Percent Stock Remaining: %f\n\r\n\r", dist_percent2); |
priyank12p | 0:b0c4c25d37ab | 144 | wait(1); |
priyank12p | 0:b0c4c25d37ab | 145 | wifi.RcvReply(rcv, 1000); |
priyank12p | 0:b0c4c25d37ab | 146 | pc.printf("%s\r", rcv); |
priyank12p | 0:b0c4c25d37ab | 147 | } |
priyank12p | 0:b0c4c25d37ab | 148 | } |