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

Dependencies:   mbed

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.

Committer:
priyank12p
Date:
Thu Dec 12 01:27:12 2019 +0000
Revision:
1:45dc700211a7
Parent:
0:b0c4c25d37ab
Minor changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
priyank12p 0:b0c4c25d37ab 1 #include "ESP8266.h"
priyank12p 0:b0c4c25d37ab 2 #define HTTPCMD "GET "
priyank12p 0:b0c4c25d37ab 3 #define protocol " HTTP/1.0\n\n"
priyank12p 0:b0c4c25d37ab 4
priyank12p 0:b0c4c25d37ab 5
priyank12p 0:b0c4c25d37ab 6 // Constructor
priyank12p 0:b0c4c25d37ab 7 ESP8266::ESP8266(PinName tx, PinName rx, int br) : comm(tx, rx) {
priyank12p 0:b0c4c25d37ab 8 comm.baud(br);
priyank12p 0:b0c4c25d37ab 9 }
priyank12p 0:b0c4c25d37ab 10
priyank12p 0:b0c4c25d37ab 11 // Destructor
priyank12p 0:b0c4c25d37ab 12 ESP8266::~ESP8266() { }
priyank12p 0:b0c4c25d37ab 13
priyank12p 0:b0c4c25d37ab 14 // Add <CR> + <LF> at the end of the string
priyank12p 0:b0c4c25d37ab 15 void ESP8266::AddEOL(char * s) {
priyank12p 0:b0c4c25d37ab 16 char k;
priyank12p 0:b0c4c25d37ab 17 k = strlen(s); // Finds position of NULL character
priyank12p 0:b0c4c25d37ab 18 s[k] = 0x0D; // switch NULL for <CR>
priyank12p 0:b0c4c25d37ab 19 s[k + 1] = 0x0A; // Add <LF>
priyank12p 0:b0c4c25d37ab 20 s[k + 2] = 0; // Add NULL at the end
priyank12p 0:b0c4c25d37ab 21 }
priyank12p 0:b0c4c25d37ab 22
priyank12p 0:b0c4c25d37ab 23 // Add one ASCII character at the end of the string
priyank12p 0:b0c4c25d37ab 24 void ESP8266::AddChar(char * s, char c) {
priyank12p 0:b0c4c25d37ab 25 char k;
priyank12p 0:b0c4c25d37ab 26 k = strlen(s);
priyank12p 0:b0c4c25d37ab 27 s[k] = c;
priyank12p 0:b0c4c25d37ab 28 s[k + 1] = 0;
priyank12p 0:b0c4c25d37ab 29 }
priyank12p 0:b0c4c25d37ab 30
priyank12p 0:b0c4c25d37ab 31 // Converts integer number to null-terminated string
priyank12p 0:b0c4c25d37ab 32 void ESP8266::itoa(int n, char * s) {
priyank12p 0:b0c4c25d37ab 33 char k = 0;
priyank12p 0:b0c4c25d37ab 34 char r[11];
priyank12p 0:b0c4c25d37ab 35
priyank12p 0:b0c4c25d37ab 36 if(n == 0) {
priyank12p 0:b0c4c25d37ab 37 s[0] = '0';
priyank12p 0:b0c4c25d37ab 38 s[1] = 0;
priyank12p 0:b0c4c25d37ab 39 } else {
priyank12p 0:b0c4c25d37ab 40 while(n != 0) {
priyank12p 0:b0c4c25d37ab 41 r[k]= (n % 10) + '0';
priyank12p 0:b0c4c25d37ab 42 n = n / 10;
priyank12p 0:b0c4c25d37ab 43 k++;
priyank12p 0:b0c4c25d37ab 44 }
priyank12p 0:b0c4c25d37ab 45 while(k > 0) {
priyank12p 0:b0c4c25d37ab 46 s[n] = r[k - 1] + '0';
priyank12p 0:b0c4c25d37ab 47 n++;
priyank12p 0:b0c4c25d37ab 48 k--;
priyank12p 0:b0c4c25d37ab 49 }
priyank12p 0:b0c4c25d37ab 50 s[n] = 0;
priyank12p 0:b0c4c25d37ab 51 }
priyank12p 0:b0c4c25d37ab 52 }
priyank12p 0:b0c4c25d37ab 53
priyank12p 0:b0c4c25d37ab 54 // Sends command to ESP8266. Receives the command string
priyank12p 0:b0c4c25d37ab 55 void ESP8266::SendCMD(char * s) {
priyank12p 0:b0c4c25d37ab 56 AddEOL(s);
priyank12p 0:b0c4c25d37ab 57 comm.printf("%s", s);
priyank12p 0:b0c4c25d37ab 58 }
priyank12p 0:b0c4c25d37ab 59
priyank12p 0:b0c4c25d37ab 60 // Resets the ESP8266
priyank12p 0:b0c4c25d37ab 61 void ESP8266::Reset(void) {
priyank12p 0:b0c4c25d37ab 62 char rs[10];
priyank12p 0:b0c4c25d37ab 63 strcpy(rs, "AT+RST");
priyank12p 0:b0c4c25d37ab 64 SendCMD(rs);
priyank12p 0:b0c4c25d37ab 65 }
priyank12p 0:b0c4c25d37ab 66
priyank12p 0:b0c4c25d37ab 67 // Receive reply until no character is received after a given timeout in miliseconds
priyank12p 0:b0c4c25d37ab 68 bool ESP8266::RcvReply(char * r, int to) {
priyank12p 0:b0c4c25d37ab 69 Timer t;
priyank12p 0:b0c4c25d37ab 70 bool ended = 0;
priyank12p 0:b0c4c25d37ab 71 char c;
priyank12p 0:b0c4c25d37ab 72
priyank12p 0:b0c4c25d37ab 73 strcpy(r, "");
priyank12p 0:b0c4c25d37ab 74 t.start();
priyank12p 0:b0c4c25d37ab 75 while(!ended) {
priyank12p 0:b0c4c25d37ab 76 if(comm.readable()) {
priyank12p 0:b0c4c25d37ab 77 c = comm.getc();
priyank12p 0:b0c4c25d37ab 78 AddChar(r, c);
priyank12p 0:b0c4c25d37ab 79 t.start();
priyank12p 0:b0c4c25d37ab 80 }
priyank12p 0:b0c4c25d37ab 81 if(t.read_ms() > to) {
priyank12p 0:b0c4c25d37ab 82 ended = 1;
priyank12p 0:b0c4c25d37ab 83 }
priyank12p 0:b0c4c25d37ab 84 }
priyank12p 0:b0c4c25d37ab 85 AddChar(r, 0x00);
priyank12p 0:b0c4c25d37ab 86 return ended;
priyank12p 0:b0c4c25d37ab 87 }
priyank12p 0:b0c4c25d37ab 88
priyank12p 0:b0c4c25d37ab 89 // Gets the AP list. Parameter: the string to receive the list
priyank12p 0:b0c4c25d37ab 90 void ESP8266::GetList(char * l) {
priyank12p 0:b0c4c25d37ab 91 char rs[15];
priyank12p 0:b0c4c25d37ab 92 strcpy(rs, "AT+CWLAP");
priyank12p 0:b0c4c25d37ab 93 SendCMD(rs);
priyank12p 0:b0c4c25d37ab 94 RcvReply(l, 5000); // Needs big timeout because it takes long to start replying
priyank12p 0:b0c4c25d37ab 95 }
priyank12p 0:b0c4c25d37ab 96
priyank12p 0:b0c4c25d37ab 97 // Joins a Wifi AP. Parameters: SSID and Password (strings)
priyank12p 0:b0c4c25d37ab 98 void ESP8266::Join(char * id, char * pwd) {
priyank12p 0:b0c4c25d37ab 99 char cmd[255];
priyank12p 0:b0c4c25d37ab 100 strcpy(cmd, "AT+CWJAP=");
priyank12p 0:b0c4c25d37ab 101 AddChar(cmd, 0x22);
priyank12p 0:b0c4c25d37ab 102 strcat(cmd, id);
priyank12p 0:b0c4c25d37ab 103 AddChar(cmd, 0x22);
priyank12p 0:b0c4c25d37ab 104 AddChar(cmd, 0x2C);
priyank12p 0:b0c4c25d37ab 105 AddChar(cmd, 0x22);
priyank12p 0:b0c4c25d37ab 106 strcat(cmd, pwd);
priyank12p 0:b0c4c25d37ab 107 AddChar(cmd, 0x22);
priyank12p 0:b0c4c25d37ab 108 SendCMD(cmd);
priyank12p 0:b0c4c25d37ab 109 }
priyank12p 0:b0c4c25d37ab 110
priyank12p 0:b0c4c25d37ab 111 // Gets ESP IP. Parameter: string to contain IP
priyank12p 0:b0c4c25d37ab 112 void ESP8266::GetIP(char * ip) {
priyank12p 0:b0c4c25d37ab 113 char cmd[15];
priyank12p 0:b0c4c25d37ab 114 strcpy(cmd, "AT+CIFSR");
priyank12p 0:b0c4c25d37ab 115 SendCMD(cmd);
priyank12p 0:b0c4c25d37ab 116 RcvReply(ip, 2000);
priyank12p 0:b0c4c25d37ab 117 }
priyank12p 0:b0c4c25d37ab 118
priyank12p 0:b0c4c25d37ab 119 //Defines wifi mode; Parameter: mode; 1= STA, 2= AP, 3=both
priyank12p 0:b0c4c25d37ab 120 void ESP8266::SetMode(char mode) {
priyank12p 0:b0c4c25d37ab 121 char cmd[15];
priyank12p 0:b0c4c25d37ab 122 strcpy(cmd, "AT+CWMODE=");
priyank12p 0:b0c4c25d37ab 123 mode = mode + 0x30; // Converts number into corresponding ASCII character
priyank12p 0:b0c4c25d37ab 124 AddChar(cmd, mode); // Completes command string
priyank12p 0:b0c4c25d37ab 125 SendCMD(cmd);
priyank12p 0:b0c4c25d37ab 126 }
priyank12p 0:b0c4c25d37ab 127
priyank12p 0:b0c4c25d37ab 128 // Quits the AP
priyank12p 0:b0c4c25d37ab 129 void ESP8266::Quit(void) {
priyank12p 0:b0c4c25d37ab 130 char cmd[15];
priyank12p 0:b0c4c25d37ab 131 strcpy(cmd, "AT+CWQAP");
priyank12p 0:b0c4c25d37ab 132 SendCMD(cmd);
priyank12p 0:b0c4c25d37ab 133 }
priyank12p 0:b0c4c25d37ab 134
priyank12p 0:b0c4c25d37ab 135 // Sets single connection
priyank12p 0:b0c4c25d37ab 136 void ESP8266::SetSingle(void) {
priyank12p 0:b0c4c25d37ab 137 char cmd[15];
priyank12p 0:b0c4c25d37ab 138 strcpy(cmd, "AT+CIPMUX=0");
priyank12p 0:b0c4c25d37ab 139 SendCMD(cmd);
priyank12p 0:b0c4c25d37ab 140 }
priyank12p 0:b0c4c25d37ab 141
priyank12p 0:b0c4c25d37ab 142 // Sets multiple connection
priyank12p 0:b0c4c25d37ab 143 void ESP8266::SetMultiple(void) {
priyank12p 0:b0c4c25d37ab 144 char rs[15];
priyank12p 0:b0c4c25d37ab 145 strcpy(rs, "AT+CIPMUX=1");
priyank12p 0:b0c4c25d37ab 146 SendCMD(rs);
priyank12p 0:b0c4c25d37ab 147 }
priyank12p 0:b0c4c25d37ab 148
priyank12p 0:b0c4c25d37ab 149 // Gets connection status. Parameter: string to contain status
priyank12p 0:b0c4c25d37ab 150 void ESP8266::GetConnStatus(char * st) {
priyank12p 0:b0c4c25d37ab 151 char cmd[15];
priyank12p 0:b0c4c25d37ab 152 strcpy(cmd, "AT+CIPSTATUS");
priyank12p 0:b0c4c25d37ab 153 SendCMD(cmd);
priyank12p 0:b0c4c25d37ab 154 RcvReply(st, 2000);
priyank12p 0:b0c4c25d37ab 155 }
priyank12p 0:b0c4c25d37ab 156
priyank12p 0:b0c4c25d37ab 157 // Starts server mode. Parameter: port to be used
priyank12p 0:b0c4c25d37ab 158 void ESP8266::StartServerMode(int port) {
priyank12p 0:b0c4c25d37ab 159 char rs[25];
priyank12p 0:b0c4c25d37ab 160 char t[4];
priyank12p 0:b0c4c25d37ab 161 strcpy(rs, "AT+CIPSERVER=1,");
priyank12p 0:b0c4c25d37ab 162 itoa(port, t);
priyank12p 0:b0c4c25d37ab 163 strcat(rs, t);
priyank12p 0:b0c4c25d37ab 164 SendCMD(rs);
priyank12p 0:b0c4c25d37ab 165 }
priyank12p 0:b0c4c25d37ab 166
priyank12p 0:b0c4c25d37ab 167 // Close server mode.
priyank12p 0:b0c4c25d37ab 168 void ESP8266::CloseServerMode(void) {
priyank12p 0:b0c4c25d37ab 169 char rs[20];
priyank12p 0:b0c4c25d37ab 170 strcpy(rs, "AT+CIPSERVER=0");
priyank12p 0:b0c4c25d37ab 171 SendCMD(rs);
priyank12p 0:b0c4c25d37ab 172 }
priyank12p 0:b0c4c25d37ab 173
priyank12p 0:b0c4c25d37ab 174 void ESP8266::setTransparent(void){
priyank12p 0:b0c4c25d37ab 175 char rs[20];
priyank12p 0:b0c4c25d37ab 176 strcpy(rs, "AT+CIPMODE=0");
priyank12p 0:b0c4c25d37ab 177 SendCMD(rs);
priyank12p 0:b0c4c25d37ab 178 }
priyank12p 0:b0c4c25d37ab 179
priyank12p 0:b0c4c25d37ab 180 void ESP8266::startTCPConn(char *IP, int port){
priyank12p 0:b0c4c25d37ab 181 char rs[100];
priyank12p 0:b0c4c25d37ab 182 sprintf(rs, "AT+CIPSTART=\"TCP\",\"%s\",%d", IP, port);
priyank12p 0:b0c4c25d37ab 183 SendCMD(rs);
priyank12p 0:b0c4c25d37ab 184 }
priyank12p 0:b0c4c25d37ab 185
priyank12p 0:b0c4c25d37ab 186 void ESP8266::sendURL(char *URL, char *command){
priyank12p 0:b0c4c25d37ab 187 char url[300], snd[300], http_cmd[300];
priyank12p 0:b0c4c25d37ab 188
priyank12p 0:b0c4c25d37ab 189 strcpy(http_cmd, HTTPCMD);
priyank12p 0:b0c4c25d37ab 190
priyank12p 0:b0c4c25d37ab 191 strcat(http_cmd, URL);
priyank12p 0:b0c4c25d37ab 192 strcat(http_cmd, protocol);
priyank12p 0:b0c4c25d37ab 193
priyank12p 0:b0c4c25d37ab 194 strcpy(url, http_cmd);
priyank12p 0:b0c4c25d37ab 195 sprintf(snd,"AT+CIPSENDEX=%d",strlen(url));
priyank12p 0:b0c4c25d37ab 196 strcpy(command, url);
priyank12p 0:b0c4c25d37ab 197 SendCMD(snd);
priyank12p 0:b0c4c25d37ab 198 wait(3);
priyank12p 0:b0c4c25d37ab 199 SendCMD(url);
priyank12p 0:b0c4c25d37ab 200 }
priyank12p 0:b0c4c25d37ab 201
priyank12p 0:b0c4c25d37ab 202