discof746 ethernet+lcd+ts2
Dependents: grove_stream_jpa_sd2 grove_stream_jpa_sd2 grove_stream_jpa_sd2-2 grove_stream_jpa_sd2-3
GroveStreams.cpp@3:494da6893902, 2021-01-13 (annotated)
- Committer:
- 38domo
- Date:
- Wed Jan 13 19:51:28 2021 +0000
- Revision:
- 3:494da6893902
- Parent:
- 2:b77ba7f2611b
update grove sreams lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mmills | 0:8b675b2726b7 | 1 | /* |
mmills | 0:8b675b2726b7 | 2 | GroveStreams is a helper class to assist with pushing data into the |
38domo | 3:494da6893902 | 3 | GroveStreams.com IoT platform. |
mmills | 0:8b675b2726b7 | 4 | */ |
mmills | 0:8b675b2726b7 | 5 | #include "GroveStreams.h" |
mmills | 0:8b675b2726b7 | 6 | GroveStreams::GroveStreams(const char* apiKey, LcdDiscoF746NgTracer* pLcd) |
38domo | 3:494da6893902 | 7 | { init(apiKey, pLcd); |
mmills | 0:8b675b2726b7 | 8 | } |
mmills | 0:8b675b2726b7 | 9 | |
mmills | 0:8b675b2726b7 | 10 | GroveStreams::GroveStreams(const char* apiKey) |
38domo | 3:494da6893902 | 11 | { init(apiKey, NULL); |
mmills | 0:8b675b2726b7 | 12 | } |
mmills | 0:8b675b2726b7 | 13 | |
mmills | 0:8b675b2726b7 | 14 | GroveStreams::~GroveStreams() { |
mmills | 0:8b675b2726b7 | 15 | _eth.disconnect(); |
mmills | 0:8b675b2726b7 | 16 | } |
mmills | 0:8b675b2726b7 | 17 | |
38domo | 1:e69854e65c88 | 18 | extern char gsStreamIPdatas[]; |
38domo | 1:e69854e65c88 | 19 | static char* _domain; |
mmills | 0:8b675b2726b7 | 20 | int GroveStreams::init(const char* apiKey, LcdDiscoF746NgTracer* pLcd) |
38domo | 3:494da6893902 | 21 | { _domain = gsStreamIPdatas; |
38domo | 1:e69854e65c88 | 22 | _port = 1880; |
mmills | 0:8b675b2726b7 | 23 | _apiKey = apiKey; |
mmills | 0:8b675b2726b7 | 24 | _myIPAddress = NULL; //Don't Change. Set below from DHCP. Needed by GroveStreams to verify that a device is not uploading more than once every 10s. |
mmills | 0:8b675b2726b7 | 25 | _pLcd = pLcd; |
mmills | 0:8b675b2726b7 | 26 | return startEthernet(); |
mmills | 0:8b675b2726b7 | 27 | } |
mmills | 0:8b675b2726b7 | 28 | |
mmills | 0:8b675b2726b7 | 29 | void GroveStreams::printf(const char* format, ...) |
38domo | 3:494da6893902 | 30 | { va_list args; |
mmills | 0:8b675b2726b7 | 31 | va_start(args, format); |
mmills | 0:8b675b2726b7 | 32 | if (_pLcd != NULL) { |
mmills | 0:8b675b2726b7 | 33 | char sbuffer[512]; |
mmills | 0:8b675b2726b7 | 34 | vsprintf(sbuffer, format, args); |
mmills | 0:8b675b2726b7 | 35 | _pLcd->println(sbuffer); |
mmills | 0:8b675b2726b7 | 36 | } else { |
mmills | 0:8b675b2726b7 | 37 | vprintf(format, args); |
mmills | 0:8b675b2726b7 | 38 | } |
mmills | 0:8b675b2726b7 | 39 | va_end(args); |
mmills | 0:8b675b2726b7 | 40 | } |
mmills | 0:8b675b2726b7 | 41 | |
mmills | 0:8b675b2726b7 | 42 | unsigned long GroveStreams::send(const char* componentId, const char* samples) |
38domo | 3:494da6893902 | 43 | { char resultBuffer[256]= {0}; |
mmills | 0:8b675b2726b7 | 44 | return send(componentId, samples, NULL, NULL, resultBuffer, sizeof resultBuffer); |
mmills | 0:8b675b2726b7 | 45 | } |
mmills | 0:8b675b2726b7 | 46 | |
38domo | 1:e69854e65c88 | 47 | unsigned long GroveStreams::sendJPA(const char* componentId, const char* samples) |
38domo | 3:494da6893902 | 48 | { char resultBuffer[256]= {0}; |
38domo | 1:e69854e65c88 | 49 | return sendJPA(componentId, samples, NULL, NULL, resultBuffer, sizeof resultBuffer); |
38domo | 1:e69854e65c88 | 50 | } |
38domo | 1:e69854e65c88 | 51 | |
38domo | 1:e69854e65c88 | 52 | unsigned long GroveStreams::sendInitDatasJPA(const char* componentId, const char* samples) |
38domo | 3:494da6893902 | 53 | { char resultBuffer[256]= {0}; |
38domo | 1:e69854e65c88 | 54 | return sendInitDatasJPA(componentId, samples, NULL, NULL, resultBuffer, sizeof resultBuffer); |
38domo | 1:e69854e65c88 | 55 | } |
38domo | 2:b77ba7f2611b | 56 | // ------------------------------------------------ |
mmills | 0:8b675b2726b7 | 57 | unsigned long GroveStreams::send(const char* componentId, const char* samples, char* resultBuffer, size_t resultBufferSize) |
38domo | 2:b77ba7f2611b | 58 | { return send(componentId, samples, NULL, NULL, resultBuffer, resultBufferSize); |
mmills | 0:8b675b2726b7 | 59 | } |
mmills | 0:8b675b2726b7 | 60 | |
mmills | 0:8b675b2726b7 | 61 | unsigned long GroveStreams::send(const char* componentId, const char* samples, const char* componentName, |
mmills | 0:8b675b2726b7 | 62 | const char* compTmplId, char* resultBuffer, size_t resultBufferSize) |
38domo | 3:494da6893902 | 63 | { int failedCounter = 0; |
mmills | 0:8b675b2726b7 | 64 | int result = 1; |
38domo | 3:494da6893902 | 65 | while (failedCounter < 3 && result != 0) { |
38domo | 3:494da6893902 | 66 | result = sendNoRetry(componentId, samples, componentName, compTmplId, resultBuffer, resultBufferSize); |
38domo | 3:494da6893902 | 67 | this->printf("send result code: %d", result); |
mmills | 0:8b675b2726b7 | 68 | if (result != 0) { |
mmills | 0:8b675b2726b7 | 69 | //Wait and try again |
mmills | 0:8b675b2726b7 | 70 | failedCounter++; |
mmills | 0:8b675b2726b7 | 71 | this->printf("send failed %d times", failedCounter); |
mmills | 0:8b675b2726b7 | 72 | wait(2); |
mmills | 0:8b675b2726b7 | 73 | } |
mmills | 0:8b675b2726b7 | 74 | if (failedCounter > 3 ) { |
mmills | 0:8b675b2726b7 | 75 | this->printf("Too many failures. Restarting Ethernet."); |
mmills | 0:8b675b2726b7 | 76 | startEthernet(); |
mmills | 0:8b675b2726b7 | 77 | } |
mmills | 0:8b675b2726b7 | 78 | } |
mmills | 0:8b675b2726b7 | 79 | return result; |
mmills | 0:8b675b2726b7 | 80 | } |
mmills | 0:8b675b2726b7 | 81 | |
38domo | 1:e69854e65c88 | 82 | unsigned long GroveStreams::sendJPA(const char* componentId, const char* samples, const char* componentName, |
38domo | 1:e69854e65c88 | 83 | const char* compTmplId, char* resultBuffer, size_t resultBufferSize) |
38domo | 3:494da6893902 | 84 | { int failedCounter = 0; |
38domo | 1:e69854e65c88 | 85 | int result = 1; |
38domo | 3:494da6893902 | 86 | while (failedCounter < 3 && result != 0) { |
38domo | 3:494da6893902 | 87 | result = sendNoRetryJPA(componentId, samples, componentName, compTmplId, resultBuffer, resultBufferSize); |
38domo | 3:494da6893902 | 88 | this->printf("send result code: %d", result); |
38domo | 1:e69854e65c88 | 89 | if (result != 0) { |
38domo | 1:e69854e65c88 | 90 | //Wait and try again |
38domo | 1:e69854e65c88 | 91 | failedCounter++; |
38domo | 1:e69854e65c88 | 92 | this->printf("send failed %d times", failedCounter); |
38domo | 1:e69854e65c88 | 93 | wait(2); |
38domo | 1:e69854e65c88 | 94 | } |
38domo | 1:e69854e65c88 | 95 | if (failedCounter > 3 ) { |
38domo | 1:e69854e65c88 | 96 | this->printf("Too many failures. Restarting Ethernet."); |
38domo | 1:e69854e65c88 | 97 | startEthernet(); |
38domo | 1:e69854e65c88 | 98 | } |
38domo | 1:e69854e65c88 | 99 | } |
38domo | 1:e69854e65c88 | 100 | return result; |
38domo | 1:e69854e65c88 | 101 | } |
38domo | 1:e69854e65c88 | 102 | |
38domo | 1:e69854e65c88 | 103 | unsigned long GroveStreams::sendInitDatasJPA(const char* componentId, const char* samples, const char* componentName, |
38domo | 1:e69854e65c88 | 104 | const char* compTmplId, char* resultBuffer, size_t resultBufferSize) |
38domo | 3:494da6893902 | 105 | { int failedCounter = 0; |
38domo | 1:e69854e65c88 | 106 | int result = 1; |
38domo | 3:494da6893902 | 107 | while (failedCounter < 3 && result != 0) { |
38domo | 3:494da6893902 | 108 | result = sendNoRetryInitDatasJPA(componentId, samples, componentName, compTmplId, resultBuffer, resultBufferSize); |
38domo | 3:494da6893902 | 109 | this->printf("send result code: %d", result); |
38domo | 1:e69854e65c88 | 110 | if (result != 0) { |
38domo | 1:e69854e65c88 | 111 | //Wait and try again |
38domo | 1:e69854e65c88 | 112 | failedCounter++; |
38domo | 1:e69854e65c88 | 113 | this->printf("send failed %d times", failedCounter); |
38domo | 1:e69854e65c88 | 114 | wait(2); |
38domo | 1:e69854e65c88 | 115 | } |
38domo | 1:e69854e65c88 | 116 | if (failedCounter > 3 ) { |
38domo | 1:e69854e65c88 | 117 | this->printf("Too many failures. Restarting Ethernet."); |
38domo | 1:e69854e65c88 | 118 | startEthernet(); |
38domo | 1:e69854e65c88 | 119 | } |
38domo | 1:e69854e65c88 | 120 | } |
38domo | 1:e69854e65c88 | 121 | return result; |
38domo | 1:e69854e65c88 | 122 | } |
38domo | 1:e69854e65c88 | 123 | |
mmills | 0:8b675b2726b7 | 124 | unsigned long GroveStreams::sendNoRetry(const char* componentId, const char* samples, const char* componentName, |
mmills | 0:8b675b2726b7 | 125 | const char* compTmplId, char* resultBuffer, size_t resultBufferSize) |
38domo | 3:494da6893902 | 126 | { //Assemble the url that is used to pass the temperature readings to GroveStreams and call it |
mmills | 0:8b675b2726b7 | 127 | network::tcp::Socket socket; |
mmills | 0:8b675b2726b7 | 128 | int openResult = socket.open(); |
mmills | 0:8b675b2726b7 | 129 | if (openResult == 0) { |
mmills | 0:8b675b2726b7 | 130 | int connResult = socket.connect(_domain, _port); |
mmills | 0:8b675b2726b7 | 131 | if(connResult == 0) { |
mmills | 0:8b675b2726b7 | 132 | char compNamePart[100] = {0}; |
mmills | 0:8b675b2726b7 | 133 | if (strlen(componentName) > 0) { |
mmills | 0:8b675b2726b7 | 134 | sprintf(compNamePart, "&compName=%s",componentName); |
mmills | 0:8b675b2726b7 | 135 | } |
mmills | 0:8b675b2726b7 | 136 | char compTmplIdPart[100] = {0}; |
mmills | 0:8b675b2726b7 | 137 | if (strlen(compTmplId) > 0) { |
mmills | 0:8b675b2726b7 | 138 | sprintf(compTmplIdPart, "&compTmplId=%s",compTmplId); |
mmills | 0:8b675b2726b7 | 139 | } |
mmills | 0:8b675b2726b7 | 140 | //You may need to increase the size of sbuffer if any other char array sizes have increased |
mmills | 0:8b675b2726b7 | 141 | char sbuffer[512]= {0}; |
38domo | 1:e69854e65c88 | 142 | sprintf(sbuffer, "PUT /stm32/datas?compId=%s%s%s&api_key=%s%s HTTP/1.1\r\nHost: \r\nConnection: close\r\nX-Forwarded-For:%s\r\n\r\n", |
38domo | 1:e69854e65c88 | 143 | componentId, compTmplIdPart, compNamePart, _apiKey, samples, _myIPAddress); |
38domo | 1:e69854e65c88 | 144 | this->printf("send sbuffer size: %d", strlen(sbuffer)); |
38domo | 1:e69854e65c88 | 145 | int scount = socket.write(sbuffer, strlen(sbuffer)); |
38domo | 1:e69854e65c88 | 146 | //this->printf("sent %d bytes: [%.*s]", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); |
38domo | 3:494da6893902 | 147 | //Read status line |
38domo | 1:e69854e65c88 | 148 | int rcount = socket.read(resultBuffer, resultBufferSize); |
38domo | 1:e69854e65c88 | 149 | this->printf("HTTP Response size: %d bytes", rcount); |
38domo | 3:494da6893902 | 150 | this->printf("HTTP Response Status:[%.*s]", strstr(resultBuffer, "\r\n")-resultBuffer, resultBuffer); |
38domo | 1:e69854e65c88 | 151 | //Only return the body |
38domo | 1:e69854e65c88 | 152 | strcpy(resultBuffer, strstr(resultBuffer, "\r\n\r\n") + strlen("\r\n\r\n")); |
38domo | 1:e69854e65c88 | 153 | strcat(resultBuffer, "\0"); |
38domo | 3:494da6893902 | 154 | //this->printf("HTTP Body: [%s]", resultBuffer); |
38domo | 1:e69854e65c88 | 155 | socket.close(); |
38domo | 1:e69854e65c88 | 156 | } else { |
38domo | 1:e69854e65c88 | 157 | |
38domo | 1:e69854e65c88 | 158 | this->printf("Socket Connect Failed: %d", connResult); |
38domo | 1:e69854e65c88 | 159 | } |
38domo | 1:e69854e65c88 | 160 | } else { |
38domo | 1:e69854e65c88 | 161 | this->printf("Socket Open Failed: %d", openResult); |
38domo | 1:e69854e65c88 | 162 | socket.close(); |
38domo | 1:e69854e65c88 | 163 | return 1; |
38domo | 1:e69854e65c88 | 164 | } |
38domo | 1:e69854e65c88 | 165 | return 0; |
38domo | 1:e69854e65c88 | 166 | } |
38domo | 1:e69854e65c88 | 167 | |
38domo | 1:e69854e65c88 | 168 | unsigned long GroveStreams::sendNoRetryJPA(const char* componentId, const char* samples, const char* componentName, |
38domo | 1:e69854e65c88 | 169 | const char* compTmplId, char* resultBuffer, size_t resultBufferSize) |
38domo | 3:494da6893902 | 170 | { //Assemble the url that is used to pass the temperature readings to GroveStreams and call it |
38domo | 1:e69854e65c88 | 171 | network::tcp::Socket socket; |
38domo | 1:e69854e65c88 | 172 | int openResult = socket.open(); |
38domo | 1:e69854e65c88 | 173 | if (openResult == 0) { |
38domo | 1:e69854e65c88 | 174 | int connResult = socket.connect(_domain, _port); |
38domo | 1:e69854e65c88 | 175 | if(connResult == 0) { |
38domo | 1:e69854e65c88 | 176 | char compNamePart[100] = {0}; |
38domo | 1:e69854e65c88 | 177 | if (strlen(componentName) > 0) { |
38domo | 1:e69854e65c88 | 178 | sprintf(compNamePart, "&compName=%s",componentName); |
38domo | 1:e69854e65c88 | 179 | } |
38domo | 1:e69854e65c88 | 180 | char compTmplIdPart[100] = {0}; |
38domo | 1:e69854e65c88 | 181 | if (strlen(compTmplId) > 0) { |
38domo | 1:e69854e65c88 | 182 | sprintf(compTmplIdPart, "&compTmplId=%s",compTmplId); |
38domo | 1:e69854e65c88 | 183 | } |
38domo | 1:e69854e65c88 | 184 | //You may need to increase the size of sbuffer if any other char array sizes have increased |
38domo | 1:e69854e65c88 | 185 | char sbuffer[512]= {0}; |
38domo | 1:e69854e65c88 | 186 | sprintf(sbuffer, "PUT /stm32/touches?compId=%s%s%s&api_key=%s%s HTTP/1.1\r\nHost: \r\nConnection: close\r\nX-Forwarded-For:%s\r\n\r\n", |
38domo | 1:e69854e65c88 | 187 | componentId, compTmplIdPart, compNamePart, _apiKey, samples, _myIPAddress); |
38domo | 1:e69854e65c88 | 188 | this->printf("send sbuffer size: %d", strlen(sbuffer)); |
38domo | 1:e69854e65c88 | 189 | int scount = socket.write(sbuffer, strlen(sbuffer)); |
38domo | 1:e69854e65c88 | 190 | //this->printf("sent %d bytes: [%.*s]", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); |
38domo | 3:494da6893902 | 191 | //Read status line |
38domo | 1:e69854e65c88 | 192 | int rcount = socket.read(resultBuffer, resultBufferSize); |
38domo | 1:e69854e65c88 | 193 | this->printf("HTTP Response size: %d bytes", rcount); |
38domo | 3:494da6893902 | 194 | this->printf("HTTP Response Status:[%.*s]", strstr(resultBuffer, "\r\n")-resultBuffer, resultBuffer); |
38domo | 1:e69854e65c88 | 195 | //Only return the body |
38domo | 1:e69854e65c88 | 196 | strcpy(resultBuffer, strstr(resultBuffer, "\r\n\r\n") + strlen("\r\n\r\n")); |
38domo | 1:e69854e65c88 | 197 | strcat(resultBuffer, "\0"); |
38domo | 3:494da6893902 | 198 | //this->printf("HTTP Body: [%s]", resultBuffer); |
38domo | 1:e69854e65c88 | 199 | socket.close(); |
38domo | 1:e69854e65c88 | 200 | } else { |
38domo | 1:e69854e65c88 | 201 | this->printf("Socket Connect Failed: %d", connResult); |
38domo | 1:e69854e65c88 | 202 | } |
38domo | 1:e69854e65c88 | 203 | } else { |
38domo | 1:e69854e65c88 | 204 | this->printf("Socket Open Failed: %d", openResult); |
38domo | 1:e69854e65c88 | 205 | socket.close(); |
38domo | 1:e69854e65c88 | 206 | return 1; |
38domo | 1:e69854e65c88 | 207 | } |
38domo | 1:e69854e65c88 | 208 | return 0; |
38domo | 1:e69854e65c88 | 209 | } |
38domo | 1:e69854e65c88 | 210 | |
38domo | 1:e69854e65c88 | 211 | unsigned long GroveStreams::sendNoRetryInitDatasJPA(const char* componentId, const char* samples, const char* componentName, |
38domo | 1:e69854e65c88 | 212 | const char* compTmplId, char* resultBuffer, size_t resultBufferSize) |
38domo | 3:494da6893902 | 213 | { //Assemble the url that is used to pass the temperature readings to GroveStreams and call it |
38domo | 1:e69854e65c88 | 214 | network::tcp::Socket socket; |
38domo | 1:e69854e65c88 | 215 | int openResult = socket.open(); |
38domo | 1:e69854e65c88 | 216 | if (openResult == 0) { |
38domo | 1:e69854e65c88 | 217 | //printf("\nConnect to socket : %s\n",_domain); |
38domo | 1:e69854e65c88 | 218 | int connResult = socket.connect(_domain, _port); |
38domo | 1:e69854e65c88 | 219 | if(connResult == 0) { |
38domo | 1:e69854e65c88 | 220 | char compNamePart[100] = {0}; |
38domo | 1:e69854e65c88 | 221 | if (strlen(componentName) > 0) { |
38domo | 1:e69854e65c88 | 222 | sprintf(compNamePart, "&compName=%s",componentName); |
38domo | 1:e69854e65c88 | 223 | } |
38domo | 1:e69854e65c88 | 224 | char compTmplIdPart[100] = {0}; |
38domo | 1:e69854e65c88 | 225 | if (strlen(compTmplId) > 0) { |
38domo | 1:e69854e65c88 | 226 | sprintf(compTmplIdPart, "&compTmplId=%s",compTmplId); |
38domo | 1:e69854e65c88 | 227 | } |
38domo | 1:e69854e65c88 | 228 | //You may need to increase the size of sbuffer if any other char array sizes have increased |
38domo | 1:e69854e65c88 | 229 | char sbuffer[512]= {0}; |
38domo | 1:e69854e65c88 | 230 | |
38domo | 1:e69854e65c88 | 231 | sprintf(sbuffer, "PUT /stm32/init?compId=%s%s%s&api_key=%s%s HTTP/1.1\r\nHost: \r\nConnection: close\r\nX-Forwarded-For:%s\r\n\r\n", |
mmills | 0:8b675b2726b7 | 232 | componentId, compTmplIdPart, compNamePart, _apiKey, samples, _myIPAddress); |
mmills | 0:8b675b2726b7 | 233 | this->printf("send sbuffer size: %d", strlen(sbuffer)); |
mmills | 0:8b675b2726b7 | 234 | int scount = socket.write(sbuffer, strlen(sbuffer)); |
mmills | 0:8b675b2726b7 | 235 | this->printf("sent %d bytes: [%.*s]", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer); |
38domo | 3:494da6893902 | 236 | //Read status line |
mmills | 0:8b675b2726b7 | 237 | int rcount = socket.read(resultBuffer, resultBufferSize); |
mmills | 0:8b675b2726b7 | 238 | this->printf("HTTP Response size: %d bytes", rcount); |
38domo | 3:494da6893902 | 239 | this->printf("HTTP Response Status:[%.*s]", strstr(resultBuffer, "\r\n")-resultBuffer, resultBuffer); |
mmills | 0:8b675b2726b7 | 240 | //Only return the body |
mmills | 0:8b675b2726b7 | 241 | strcpy(resultBuffer, strstr(resultBuffer, "\r\n\r\n") + strlen("\r\n\r\n")); |
mmills | 0:8b675b2726b7 | 242 | strcat(resultBuffer, "\0"); |
38domo | 3:494da6893902 | 243 | this->printf("HTTP Body: [%s]", resultBuffer); |
mmills | 0:8b675b2726b7 | 244 | socket.close(); |
mmills | 0:8b675b2726b7 | 245 | } else { |
mmills | 0:8b675b2726b7 | 246 | this->printf("Socket Connect Failed: %d", connResult); |
mmills | 0:8b675b2726b7 | 247 | } |
mmills | 0:8b675b2726b7 | 248 | } else { |
mmills | 0:8b675b2726b7 | 249 | this->printf("Socket Open Failed: %d", openResult); |
mmills | 0:8b675b2726b7 | 250 | socket.close(); |
mmills | 0:8b675b2726b7 | 251 | return 1; |
mmills | 0:8b675b2726b7 | 252 | } |
mmills | 0:8b675b2726b7 | 253 | return 0; |
mmills | 0:8b675b2726b7 | 254 | } |
mmills | 0:8b675b2726b7 | 255 | int GroveStreams::startEthernet() |
38domo | 3:494da6893902 | 256 | { //Start or restart the Ethernet connection. |
mmills | 0:8b675b2726b7 | 257 | int result = _eth.disconnect(); |
mmills | 0:8b675b2726b7 | 258 | if (result != 0) { |
mmills | 0:8b675b2726b7 | 259 | this->printf("Ethernet diconnect Failed: %d", result); |
mmills | 0:8b675b2726b7 | 260 | return result; |
mmills | 0:8b675b2726b7 | 261 | } |
mmills | 0:8b675b2726b7 | 262 | this->printf("Connecting STM32 to network..."); |
mmills | 0:8b675b2726b7 | 263 | //Connect to the network and obtain an IP address using DHCP |
mmills | 0:8b675b2726b7 | 264 | result = _eth.init(); |
mmills | 0:8b675b2726b7 | 265 | if (result != 0) { |
mmills | 0:8b675b2726b7 | 266 | this->printf("Ethernet init Failed: %d", result); |
mmills | 0:8b675b2726b7 | 267 | return result; |
mmills | 0:8b675b2726b7 | 268 | } |
mmills | 0:8b675b2726b7 | 269 | result = _eth.connect(); |
mmills | 0:8b675b2726b7 | 270 | if (result != 0) { |
mmills | 0:8b675b2726b7 | 271 | this->printf("Ethernet connect Failed: %d", result); |
mmills | 0:8b675b2726b7 | 272 | return result; |
mmills | 0:8b675b2726b7 | 273 | } else { |
mmills | 0:8b675b2726b7 | 274 | this->printf("STM32 connected to network"); |
mmills | 0:8b675b2726b7 | 275 | //Set the mac and ip variables so that they can be used during sensor uploads later |
mmills | 0:8b675b2726b7 | 276 | _myIPAddress = _eth.getIPAddress(); |
mmills | 0:8b675b2726b7 | 277 | this->printf("IP address: %s", _myIPAddress ? _myIPAddress : "No IP"); |
mmills | 0:8b675b2726b7 | 278 | } |
mmills | 0:8b675b2726b7 | 279 | return 0; |
mmills | 0:8b675b2726b7 | 280 | } |
38domo | 3:494da6893902 | 281 | const char* GroveStreams::getMACAddress() |
38domo | 3:494da6893902 | 282 | { return _eth.getMACAddress(); |
38domo | 3:494da6893902 | 283 | } |
mmills | 0:8b675b2726b7 | 284 |