![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
WIZwiki-REST-io ver.2 Add POST Method
Dependencies: MbedJSONValue_copy WIZnetInterface mbed
Fork of WIZwiki-REST_mc by
main.cpp@2:ca36ecca24c2, 2016-05-03 (annotated)
- Committer:
- joon874
- Date:
- Tue May 03 02:15:59 2016 +0000
- Revision:
- 2:ca36ecca24c2
- Parent:
- 1:728e5b5c8dae
- Child:
- 4:0b5a199e91f3
Revision 2016.05.03
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joon874 | 0:5886f525a4ad | 1 | #include "mbed.h" |
joon874 | 0:5886f525a4ad | 2 | #include "HTTPServer.h" |
joon874 | 0:5886f525a4ad | 3 | #include "RequestHandler.h" |
joon874 | 0:5886f525a4ad | 4 | #include "EthernetInterface.h" |
joon874 | 0:5886f525a4ad | 5 | #include "MbedJSONValue.h" |
joon874 | 0:5886f525a4ad | 6 | |
joon874 | 0:5886f525a4ad | 7 | #define SERVER_PORT 80 |
joon874 | 0:5886f525a4ad | 8 | |
joon874 | 2:ca36ecca24c2 | 9 | #define DHCP |
joon874 | 2:ca36ecca24c2 | 10 | |
joon874 | 0:5886f525a4ad | 11 | EthernetInterface eth; |
joon874 | 0:5886f525a4ad | 12 | HTTPServer WIZwikiWebSvr; |
joon874 | 0:5886f525a4ad | 13 | MbedJSONValue WIZwikiREST; |
joon874 | 0:5886f525a4ad | 14 | |
joon874 | 0:5886f525a4ad | 15 | // Enter a MAC address for your controller below. |
joon874 | 0:5886f525a4ad | 16 | uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0xFE}; |
joon874 | 0:5886f525a4ad | 17 | char mac_str[20]; |
joon874 | 0:5886f525a4ad | 18 | char ip_addr[] = "192.168.100.100"; |
joon874 | 0:5886f525a4ad | 19 | char subnet_mask[] = "255.255.255.0"; |
joon874 | 0:5886f525a4ad | 20 | char gateway_addr[] = "192.168.100.1"; |
joon874 | 0:5886f525a4ad | 21 | |
joon874 | 0:5886f525a4ad | 22 | DigitalOut LED_1(PA_1); |
joon874 | 0:5886f525a4ad | 23 | DigitalOut LED_2(PA_2); |
joon874 | 0:5886f525a4ad | 24 | |
MidnightCow | 1:728e5b5c8dae | 25 | DigitalInOut GP05(P5); |
MidnightCow | 1:728e5b5c8dae | 26 | DigitalInOut GP06(P6); |
MidnightCow | 1:728e5b5c8dae | 27 | DigitalInOut GP07(P7); |
MidnightCow | 1:728e5b5c8dae | 28 | DigitalInOut GP08(P8); |
MidnightCow | 1:728e5b5c8dae | 29 | DigitalInOut GP09(P9); |
MidnightCow | 1:728e5b5c8dae | 30 | DigitalInOut GP10(P10); |
MidnightCow | 1:728e5b5c8dae | 31 | DigitalInOut GP11(P11); |
MidnightCow | 1:728e5b5c8dae | 32 | DigitalInOut GP12(P12); |
MidnightCow | 1:728e5b5c8dae | 33 | DigitalInOut GP13(P13); |
MidnightCow | 1:728e5b5c8dae | 34 | DigitalInOut GP14(P14); |
MidnightCow | 1:728e5b5c8dae | 35 | DigitalInOut GP15(P15); |
MidnightCow | 1:728e5b5c8dae | 36 | DigitalInOut GP16(P16); |
MidnightCow | 1:728e5b5c8dae | 37 | DigitalInOut GP17(P17); |
MidnightCow | 1:728e5b5c8dae | 38 | DigitalInOut GP18(P18); |
MidnightCow | 1:728e5b5c8dae | 39 | DigitalInOut GP19(P19); |
MidnightCow | 1:728e5b5c8dae | 40 | DigitalInOut GP20(P20); |
MidnightCow | 1:728e5b5c8dae | 41 | DigitalInOut GP21(P21); |
MidnightCow | 1:728e5b5c8dae | 42 | DigitalInOut GP22(P22); |
MidnightCow | 1:728e5b5c8dae | 43 | DigitalInOut GP23(P23); |
MidnightCow | 1:728e5b5c8dae | 44 | DigitalInOut GP24(P24); |
MidnightCow | 1:728e5b5c8dae | 45 | DigitalInOut GP25(P25); |
MidnightCow | 1:728e5b5c8dae | 46 | DigitalInOut GP26(P26); |
MidnightCow | 1:728e5b5c8dae | 47 | DigitalInOut GP27(P27); |
MidnightCow | 1:728e5b5c8dae | 48 | DigitalInOut GP28(P28); |
MidnightCow | 1:728e5b5c8dae | 49 | DigitalInOut GP29(P29); |
MidnightCow | 1:728e5b5c8dae | 50 | DigitalInOut GP30(P30); |
MidnightCow | 1:728e5b5c8dae | 51 | DigitalInOut GP31(P31); |
MidnightCow | 1:728e5b5c8dae | 52 | DigitalInOut GP32(P32); |
joon874 | 0:5886f525a4ad | 53 | |
MidnightCow | 1:728e5b5c8dae | 54 | bool p5_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 55 | { |
MidnightCow | 1:728e5b5c8dae | 56 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 57 | GP05.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 58 | return true; |
MidnightCow | 1:728e5b5c8dae | 59 | } |
MidnightCow | 1:728e5b5c8dae | 60 | bool p6_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 61 | { |
MidnightCow | 1:728e5b5c8dae | 62 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 63 | GP06.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 64 | return true; |
MidnightCow | 1:728e5b5c8dae | 65 | } |
MidnightCow | 1:728e5b5c8dae | 66 | bool p7_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 67 | { |
MidnightCow | 1:728e5b5c8dae | 68 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 69 | GP07.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 70 | return true; |
MidnightCow | 1:728e5b5c8dae | 71 | } |
MidnightCow | 1:728e5b5c8dae | 72 | bool p8_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 73 | { |
MidnightCow | 1:728e5b5c8dae | 74 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 75 | GP08.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 76 | return true; |
MidnightCow | 1:728e5b5c8dae | 77 | } |
MidnightCow | 1:728e5b5c8dae | 78 | bool p9_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 79 | { |
MidnightCow | 1:728e5b5c8dae | 80 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 81 | GP09.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 82 | return true; |
MidnightCow | 1:728e5b5c8dae | 83 | } |
MidnightCow | 1:728e5b5c8dae | 84 | bool p10_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 85 | { |
MidnightCow | 1:728e5b5c8dae | 86 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 87 | GP10.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 88 | return true; |
MidnightCow | 1:728e5b5c8dae | 89 | } |
MidnightCow | 1:728e5b5c8dae | 90 | bool p11_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 91 | { |
MidnightCow | 1:728e5b5c8dae | 92 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 93 | GP11.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 94 | return true; |
MidnightCow | 1:728e5b5c8dae | 95 | } |
MidnightCow | 1:728e5b5c8dae | 96 | bool p12_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 97 | { |
MidnightCow | 1:728e5b5c8dae | 98 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 99 | GP12.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 100 | return true; |
MidnightCow | 1:728e5b5c8dae | 101 | } |
MidnightCow | 1:728e5b5c8dae | 102 | bool p13_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 103 | { |
MidnightCow | 1:728e5b5c8dae | 104 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 105 | GP13.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 106 | return true; |
MidnightCow | 1:728e5b5c8dae | 107 | } |
MidnightCow | 1:728e5b5c8dae | 108 | bool p14_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 109 | { |
MidnightCow | 1:728e5b5c8dae | 110 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 111 | GP14.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 112 | return true; |
MidnightCow | 1:728e5b5c8dae | 113 | } |
MidnightCow | 1:728e5b5c8dae | 114 | bool p15_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 115 | { |
MidnightCow | 1:728e5b5c8dae | 116 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 117 | GP15.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 118 | return true; |
MidnightCow | 1:728e5b5c8dae | 119 | } |
MidnightCow | 1:728e5b5c8dae | 120 | bool p16_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 121 | { |
MidnightCow | 1:728e5b5c8dae | 122 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 123 | GP16.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 124 | return true; |
MidnightCow | 1:728e5b5c8dae | 125 | } |
MidnightCow | 1:728e5b5c8dae | 126 | bool p17_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 127 | { |
MidnightCow | 1:728e5b5c8dae | 128 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 129 | GP17.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 130 | return true; |
MidnightCow | 1:728e5b5c8dae | 131 | } |
MidnightCow | 1:728e5b5c8dae | 132 | bool p18_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 133 | { |
MidnightCow | 1:728e5b5c8dae | 134 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 135 | GP18.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 136 | return true; |
MidnightCow | 1:728e5b5c8dae | 137 | } |
MidnightCow | 1:728e5b5c8dae | 138 | bool p19_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 139 | { |
MidnightCow | 1:728e5b5c8dae | 140 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 141 | GP19.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 142 | return true; |
MidnightCow | 1:728e5b5c8dae | 143 | } |
MidnightCow | 1:728e5b5c8dae | 144 | bool p20_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 145 | { |
MidnightCow | 1:728e5b5c8dae | 146 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 147 | GP20.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 148 | return true; |
MidnightCow | 1:728e5b5c8dae | 149 | } |
MidnightCow | 1:728e5b5c8dae | 150 | bool p21_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 151 | { |
MidnightCow | 1:728e5b5c8dae | 152 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 153 | GP21.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 154 | return true; |
MidnightCow | 1:728e5b5c8dae | 155 | } |
MidnightCow | 1:728e5b5c8dae | 156 | bool p22_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 157 | { |
MidnightCow | 1:728e5b5c8dae | 158 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 159 | GP22.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 160 | return true; |
MidnightCow | 1:728e5b5c8dae | 161 | } |
MidnightCow | 1:728e5b5c8dae | 162 | bool p23_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 163 | { |
MidnightCow | 1:728e5b5c8dae | 164 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 165 | GP23.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 166 | return true; |
MidnightCow | 1:728e5b5c8dae | 167 | } |
MidnightCow | 1:728e5b5c8dae | 168 | bool p24_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 169 | { |
MidnightCow | 1:728e5b5c8dae | 170 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 171 | GP24.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 172 | return true; |
MidnightCow | 1:728e5b5c8dae | 173 | } |
MidnightCow | 1:728e5b5c8dae | 174 | bool p25_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 175 | { |
MidnightCow | 1:728e5b5c8dae | 176 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 177 | GP25.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 178 | return true; |
MidnightCow | 1:728e5b5c8dae | 179 | } |
MidnightCow | 1:728e5b5c8dae | 180 | bool p26_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 181 | { |
MidnightCow | 1:728e5b5c8dae | 182 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 183 | GP26.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 184 | return true; |
MidnightCow | 1:728e5b5c8dae | 185 | } |
MidnightCow | 1:728e5b5c8dae | 186 | bool p27_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 187 | { |
MidnightCow | 1:728e5b5c8dae | 188 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 189 | GP27.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 190 | return true; |
MidnightCow | 1:728e5b5c8dae | 191 | } |
MidnightCow | 1:728e5b5c8dae | 192 | bool p28_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 193 | { |
MidnightCow | 1:728e5b5c8dae | 194 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 195 | GP28.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 196 | return true; |
MidnightCow | 1:728e5b5c8dae | 197 | } |
MidnightCow | 1:728e5b5c8dae | 198 | bool p29_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 199 | { |
MidnightCow | 1:728e5b5c8dae | 200 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 201 | GP29.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 202 | return true; |
MidnightCow | 1:728e5b5c8dae | 203 | } |
MidnightCow | 1:728e5b5c8dae | 204 | bool p30_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 205 | { |
MidnightCow | 1:728e5b5c8dae | 206 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 207 | GP30.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 208 | return true; |
MidnightCow | 1:728e5b5c8dae | 209 | } |
MidnightCow | 1:728e5b5c8dae | 210 | bool p31_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 211 | { |
MidnightCow | 1:728e5b5c8dae | 212 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 213 | GP31.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 214 | return true; |
MidnightCow | 1:728e5b5c8dae | 215 | } |
MidnightCow | 1:728e5b5c8dae | 216 | bool p32_set(void* param) |
MidnightCow | 1:728e5b5c8dae | 217 | { |
MidnightCow | 1:728e5b5c8dae | 218 | if(!param) return false; |
MidnightCow | 1:728e5b5c8dae | 219 | GP32.write(*(int*)param); |
MidnightCow | 1:728e5b5c8dae | 220 | return true; |
MidnightCow | 1:728e5b5c8dae | 221 | } |
MidnightCow | 1:728e5b5c8dae | 222 | |
MidnightCow | 1:728e5b5c8dae | 223 | void debug_info() |
MidnightCow | 1:728e5b5c8dae | 224 | { |
MidnightCow | 1:728e5b5c8dae | 225 | printf("SP:0x%X\r\n",__current_sp()); |
MidnightCow | 1:728e5b5c8dae | 226 | __heapstats((__heapprt)fprintf,stderr); |
MidnightCow | 1:728e5b5c8dae | 227 | printf("\r\n"); |
MidnightCow | 1:728e5b5c8dae | 228 | } |
joon874 | 0:5886f525a4ad | 229 | void WIZwiki_REST_init(); |
joon874 | 0:5886f525a4ad | 230 | |
joon874 | 0:5886f525a4ad | 231 | int main(void) |
joon874 | 0:5886f525a4ad | 232 | { |
joon874 | 2:ca36ecca24c2 | 233 | |
joon874 | 0:5886f525a4ad | 234 | sprintf(mac_str, "%02X:%02X:%02X:%02X:%02X:%02X",mac_addr[0],mac_addr[1], |
joon874 | 0:5886f525a4ad | 235 | mac_addr[2],mac_addr[3], |
joon874 | 0:5886f525a4ad | 236 | mac_addr[4],mac_addr[5]); |
joon874 | 0:5886f525a4ad | 237 | //GPIO Set |
MidnightCow | 1:728e5b5c8dae | 238 | GP05.output(); |
joon874 | 2:ca36ecca24c2 | 239 | GP05.write(1); |
joon874 | 2:ca36ecca24c2 | 240 | GP06.output(); |
joon874 | 2:ca36ecca24c2 | 241 | GP06.write(1); |
joon874 | 2:ca36ecca24c2 | 242 | GP07.output(); |
joon874 | 2:ca36ecca24c2 | 243 | GP07.write(1); |
joon874 | 2:ca36ecca24c2 | 244 | GP08.output(); |
joon874 | 2:ca36ecca24c2 | 245 | GP08.write(1); |
joon874 | 2:ca36ecca24c2 | 246 | GP09.output(); |
joon874 | 2:ca36ecca24c2 | 247 | GP09.write(1); |
joon874 | 2:ca36ecca24c2 | 248 | GP10.output(); |
joon874 | 2:ca36ecca24c2 | 249 | GP10.write(1); |
joon874 | 2:ca36ecca24c2 | 250 | GP11.output(); |
joon874 | 2:ca36ecca24c2 | 251 | GP11.write(1); |
joon874 | 2:ca36ecca24c2 | 252 | GP12.output(); |
joon874 | 2:ca36ecca24c2 | 253 | GP12.write(1); |
joon874 | 2:ca36ecca24c2 | 254 | GP13.output(); |
joon874 | 2:ca36ecca24c2 | 255 | GP13.write(1); |
joon874 | 2:ca36ecca24c2 | 256 | GP14.output(); |
joon874 | 2:ca36ecca24c2 | 257 | GP14.write(1); |
joon874 | 2:ca36ecca24c2 | 258 | GP15.output(); |
joon874 | 2:ca36ecca24c2 | 259 | GP15.write(1); |
joon874 | 2:ca36ecca24c2 | 260 | GP16.output(); |
joon874 | 2:ca36ecca24c2 | 261 | GP16.write(1); |
joon874 | 2:ca36ecca24c2 | 262 | GP17.output(); |
joon874 | 2:ca36ecca24c2 | 263 | GP17.write(1); |
joon874 | 2:ca36ecca24c2 | 264 | GP18.output(); |
joon874 | 2:ca36ecca24c2 | 265 | GP18.write(1); |
joon874 | 2:ca36ecca24c2 | 266 | GP19.output(); |
joon874 | 2:ca36ecca24c2 | 267 | GP19.write(1); |
joon874 | 2:ca36ecca24c2 | 268 | GP20.output(); |
joon874 | 2:ca36ecca24c2 | 269 | GP20.write(1); |
joon874 | 2:ca36ecca24c2 | 270 | GP21.output(); |
joon874 | 2:ca36ecca24c2 | 271 | GP21.write(1); |
joon874 | 2:ca36ecca24c2 | 272 | GP22.output(); |
joon874 | 2:ca36ecca24c2 | 273 | GP22.write(1); |
joon874 | 2:ca36ecca24c2 | 274 | GP23.output(); |
joon874 | 2:ca36ecca24c2 | 275 | GP23.write(1); |
joon874 | 2:ca36ecca24c2 | 276 | GP24.output(); |
joon874 | 2:ca36ecca24c2 | 277 | GP24.write(1); |
joon874 | 2:ca36ecca24c2 | 278 | GP25.output(); |
joon874 | 2:ca36ecca24c2 | 279 | GP25.write(1); |
joon874 | 2:ca36ecca24c2 | 280 | GP26.output(); |
joon874 | 2:ca36ecca24c2 | 281 | GP26.write(1); |
joon874 | 2:ca36ecca24c2 | 282 | GP27.output(); |
joon874 | 2:ca36ecca24c2 | 283 | GP27.write(1); |
joon874 | 2:ca36ecca24c2 | 284 | GP28.output(); |
joon874 | 2:ca36ecca24c2 | 285 | GP28.write(1); |
joon874 | 2:ca36ecca24c2 | 286 | GP29.output(); |
joon874 | 2:ca36ecca24c2 | 287 | GP29.write(1); |
joon874 | 2:ca36ecca24c2 | 288 | |
MidnightCow | 1:728e5b5c8dae | 289 | |
joon874 | 0:5886f525a4ad | 290 | //LED Setbit |
joon874 | 0:5886f525a4ad | 291 | LED_1.write(0); // LED On |
joon874 | 0:5886f525a4ad | 292 | LED_2.write(1); // LED Off |
MidnightCow | 1:728e5b5c8dae | 293 | printf("START \r\n"); |
MidnightCow | 1:728e5b5c8dae | 294 | printf("sizeof(MbedJSONValue)=%d\r\n",sizeof(MbedJSONValue)); |
MidnightCow | 1:728e5b5c8dae | 295 | printf("sizeof(vector)=%d\r\n",sizeof(std::vector<string*>)); |
MidnightCow | 1:728e5b5c8dae | 296 | printf("sizeof(string)=%d\r\n",sizeof(std::string)); |
MidnightCow | 1:728e5b5c8dae | 297 | debug_info(); |
joon874 | 0:5886f525a4ad | 298 | |
joon874 | 0:5886f525a4ad | 299 | WIZwiki_REST_init(); |
MidnightCow | 1:728e5b5c8dae | 300 | |
MidnightCow | 1:728e5b5c8dae | 301 | debug_info(); |
MidnightCow | 1:728e5b5c8dae | 302 | |
joon874 | 0:5886f525a4ad | 303 | // Serialize it into a JSON string |
joon874 | 0:5886f525a4ad | 304 | printf("\r\n"); |
joon874 | 0:5886f525a4ad | 305 | printf("-------------------------WIZwikiREST--------------------------- \r\n"); |
joon874 | 0:5886f525a4ad | 306 | printf("%s\r\n", WIZwikiREST.serialize().c_str()); |
joon874 | 0:5886f525a4ad | 307 | printf("--------------------------------------------------------------- \r\n"); |
joon874 | 0:5886f525a4ad | 308 | |
joon874 | 0:5886f525a4ad | 309 | WIZwikiWebSvr.add_request_handler("GET", new GetRequestHandler()); |
joon874 | 0:5886f525a4ad | 310 | //WIZwikiWebSvr.add_request_handler("DELETE", new DeleteRequestHandler()); |
joon874 | 0:5886f525a4ad | 311 | //WIZwikiWebSvr.add_request_handler("PUT", new PutRequestHandler()); |
joon874 | 0:5886f525a4ad | 312 | |
joon874 | 0:5886f525a4ad | 313 | #ifdef DHCP |
joon874 | 0:5886f525a4ad | 314 | eth.init(mac_addr); //Use DHCP |
joon874 | 0:5886f525a4ad | 315 | #else |
joon874 | 0:5886f525a4ad | 316 | eth.init(mac_addr, ip_addr, subnet_mask, gateway_addr); //Not Use DHCP |
joon874 | 0:5886f525a4ad | 317 | #endif |
joon874 | 0:5886f525a4ad | 318 | |
joon874 | 2:ca36ecca24c2 | 319 | |
joon874 | 0:5886f525a4ad | 320 | printf("Check Ethernet Link\r\n"); |
joon874 | 2:ca36ecca24c2 | 321 | //Add |
joon874 | 2:ca36ecca24c2 | 322 | do{ |
joon874 | 2:ca36ecca24c2 | 323 | printf(" Link - Wait... \r\n"); |
joon874 | 2:ca36ecca24c2 | 324 | wait(1); |
joon874 | 2:ca36ecca24c2 | 325 | }while(!eth.ethernet_link()); |
joon874 | 2:ca36ecca24c2 | 326 | printf("-- Ethetnet PHY Link - Done -- \r\n"); |
joon874 | 2:ca36ecca24c2 | 327 | |
joon874 | 2:ca36ecca24c2 | 328 | if (eth.connect() < 0 ) |
joon874 | 2:ca36ecca24c2 | 329 | printf("-- EThernet Connect - Fail -- \r\n"); |
joon874 | 2:ca36ecca24c2 | 330 | else |
joon874 | 0:5886f525a4ad | 331 | { |
joon874 | 2:ca36ecca24c2 | 332 | printf("-- Assigned Network Information -- \r\n"); |
joon874 | 2:ca36ecca24c2 | 333 | printf(" IP : %s\r\n\r\n", eth.getIPAddress()); |
joon874 | 2:ca36ecca24c2 | 334 | printf(" MASK : %s\r\n\r\n", eth.getNetworkMask()); |
joon874 | 2:ca36ecca24c2 | 335 | printf(" GW : %s\r\n\r\n", eth.getGateway()); |
joon874 | 0:5886f525a4ad | 336 | } |
joon874 | 2:ca36ecca24c2 | 337 | |
joon874 | 2:ca36ecca24c2 | 338 | //while(1) //Wait link up |
joon874 | 2:ca36ecca24c2 | 339 | //{ |
joon874 | 2:ca36ecca24c2 | 340 | // if(eth.link() == true) |
joon874 | 2:ca36ecca24c2 | 341 | // break; |
joon874 | 2:ca36ecca24c2 | 342 | //} |
joon874 | 0:5886f525a4ad | 343 | |
joon874 | 0:5886f525a4ad | 344 | printf("Link up\r\n"); |
joon874 | 0:5886f525a4ad | 345 | printf("IP Address is %s\r\n", eth.getIPAddress()); |
joon874 | 0:5886f525a4ad | 346 | |
joon874 | 0:5886f525a4ad | 347 | if(!WIZwikiWebSvr.init(SERVER_PORT)) |
joon874 | 0:5886f525a4ad | 348 | { |
joon874 | 0:5886f525a4ad | 349 | eth.disconnect(); |
joon874 | 0:5886f525a4ad | 350 | return -1; |
joon874 | 0:5886f525a4ad | 351 | } |
joon874 | 0:5886f525a4ad | 352 | |
joon874 | 0:5886f525a4ad | 353 | while(1) |
joon874 | 0:5886f525a4ad | 354 | { |
joon874 | 0:5886f525a4ad | 355 | WIZwikiWebSvr.run(); |
joon874 | 0:5886f525a4ad | 356 | } |
joon874 | 0:5886f525a4ad | 357 | } |
joon874 | 0:5886f525a4ad | 358 | |
joon874 | 0:5886f525a4ad | 359 | void WIZwiki_REST_init(void) |
joon874 | 0:5886f525a4ad | 360 | { |
joon874 | 0:5886f525a4ad | 361 | //Fill the object |
MidnightCow | 1:728e5b5c8dae | 362 | WIZwikiREST["Name"] = "WIZwiki-RESTful-01"; |
MidnightCow | 1:728e5b5c8dae | 363 | WIZwikiREST["Name"].accessible = false; |
MidnightCow | 1:728e5b5c8dae | 364 | debug_info(); |
MidnightCow | 1:728e5b5c8dae | 365 | |
joon874 | 0:5886f525a4ad | 366 | //Network |
MidnightCow | 1:728e5b5c8dae | 367 | |
joon874 | 0:5886f525a4ad | 368 | WIZwikiREST["Network"]["MAC"] = mac_str; |
MidnightCow | 1:728e5b5c8dae | 369 | debug_info(); |
joon874 | 0:5886f525a4ad | 370 | WIZwikiREST["Network"]["IP"] = ip_addr; |
MidnightCow | 1:728e5b5c8dae | 371 | WIZwikiREST["Network"]["IP"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 372 | debug_info(); |
joon874 | 0:5886f525a4ad | 373 | WIZwikiREST["Network"]["SN"] = subnet_mask; |
MidnightCow | 1:728e5b5c8dae | 374 | WIZwikiREST["Network"]["SN"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 375 | debug_info(); |
joon874 | 0:5886f525a4ad | 376 | WIZwikiREST["Network"]["GW"] = gateway_addr; |
MidnightCow | 1:728e5b5c8dae | 377 | WIZwikiREST["Network"]["GW"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 378 | debug_info(); |
MidnightCow | 1:728e5b5c8dae | 379 | |
joon874 | 0:5886f525a4ad | 380 | //LEDs |
MidnightCow | 1:728e5b5c8dae | 381 | WIZwikiREST["LED1"] = (LED_1.read() ? "Off" : "On"); |
MidnightCow | 1:728e5b5c8dae | 382 | WIZwikiREST["LED1"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 383 | debug_info(); |
MidnightCow | 1:728e5b5c8dae | 384 | WIZwikiREST["LED2"] = (LED_2.read() ? "Off" : "On"); |
MidnightCow | 1:728e5b5c8dae | 385 | WIZwikiREST["LED2"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 386 | debug_info(); |
joon874 | 0:5886f525a4ad | 387 | // GPIOs |
MidnightCow | 1:728e5b5c8dae | 388 | WIZwikiREST["GPIOs"]["P05"] = GP05.read(); |
MidnightCow | 1:728e5b5c8dae | 389 | WIZwikiREST["GPIOs"]["P05"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 390 | WIZwikiREST["GPIOs"]["P05"].cb_action = p5_set; |
MidnightCow | 1:728e5b5c8dae | 391 | WIZwikiREST["GPIOs"]["P06"] = GP06.read(); |
MidnightCow | 1:728e5b5c8dae | 392 | WIZwikiREST["GPIOs"]["P06"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 393 | WIZwikiREST["GPIOs"]["P06"].cb_action = p6_set; |
MidnightCow | 1:728e5b5c8dae | 394 | WIZwikiREST["GPIOs"]["P07"] = GP07.read(); |
MidnightCow | 1:728e5b5c8dae | 395 | WIZwikiREST["GPIOs"]["P07"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 396 | WIZwikiREST["GPIOs"]["P07"].cb_action = p7_set; |
MidnightCow | 1:728e5b5c8dae | 397 | WIZwikiREST["GPIOs"]["P08"] = GP08.read(); |
MidnightCow | 1:728e5b5c8dae | 398 | WIZwikiREST["GPIOs"]["P08"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 399 | WIZwikiREST["GPIOs"]["P08"].cb_action = p8_set; |
MidnightCow | 1:728e5b5c8dae | 400 | WIZwikiREST["GPIOs"]["P09"] = GP09.read(); |
MidnightCow | 1:728e5b5c8dae | 401 | WIZwikiREST["GPIOs"]["P09"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 402 | WIZwikiREST["GPIOs"]["P09"].cb_action = p9_set; |
MidnightCow | 1:728e5b5c8dae | 403 | WIZwikiREST["GPIOs"]["P10"] = GP10.read(); |
MidnightCow | 1:728e5b5c8dae | 404 | WIZwikiREST["GPIOs"]["P10"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 405 | WIZwikiREST["GPIOs"]["P10"].cb_action = p10_set; |
MidnightCow | 1:728e5b5c8dae | 406 | WIZwikiREST["GPIOs"]["P11"] = GP11.read(); |
MidnightCow | 1:728e5b5c8dae | 407 | WIZwikiREST["GPIOs"]["P11"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 408 | WIZwikiREST["GPIOs"]["P11"].cb_action = p11_set; |
MidnightCow | 1:728e5b5c8dae | 409 | WIZwikiREST["GPIOs"]["P12"] = GP12.read(); |
MidnightCow | 1:728e5b5c8dae | 410 | WIZwikiREST["GPIOs"]["P12"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 411 | WIZwikiREST["GPIOs"]["P12"].cb_action = p12_set; |
MidnightCow | 1:728e5b5c8dae | 412 | WIZwikiREST["GPIOs"]["P13"] = GP13.read(); |
MidnightCow | 1:728e5b5c8dae | 413 | WIZwikiREST["GPIOs"]["P13"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 414 | WIZwikiREST["GPIOs"]["P13"].cb_action = p13_set; |
MidnightCow | 1:728e5b5c8dae | 415 | WIZwikiREST["GPIOs"]["P14"] = GP14.read(); |
MidnightCow | 1:728e5b5c8dae | 416 | WIZwikiREST["GPIOs"]["P14"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 417 | WIZwikiREST["GPIOs"]["P14"].cb_action = p14_set; |
MidnightCow | 1:728e5b5c8dae | 418 | WIZwikiREST["GPIOs"]["P15"] = GP15.read(); |
MidnightCow | 1:728e5b5c8dae | 419 | WIZwikiREST["GPIOs"]["P15"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 420 | WIZwikiREST["GPIOs"]["P15"].cb_action = p15_set; |
MidnightCow | 1:728e5b5c8dae | 421 | WIZwikiREST["GPIOs"]["P16"] = GP16.read(); |
MidnightCow | 1:728e5b5c8dae | 422 | WIZwikiREST["GPIOs"]["P16"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 423 | WIZwikiREST["GPIOs"]["P16"].cb_action = p16_set; |
MidnightCow | 1:728e5b5c8dae | 424 | WIZwikiREST["GPIOs"]["P17"] = GP17.read(); |
MidnightCow | 1:728e5b5c8dae | 425 | WIZwikiREST["GPIOs"]["P17"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 426 | WIZwikiREST["GPIOs"]["P17"].cb_action = p17_set; |
MidnightCow | 1:728e5b5c8dae | 427 | WIZwikiREST["GPIOs"]["P18"] = GP18.read(); |
MidnightCow | 1:728e5b5c8dae | 428 | WIZwikiREST["GPIOs"]["P18"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 429 | WIZwikiREST["GPIOs"]["P18"].cb_action = p18_set; |
MidnightCow | 1:728e5b5c8dae | 430 | WIZwikiREST["GPIOs"]["P19"] = GP19.read(); |
MidnightCow | 1:728e5b5c8dae | 431 | WIZwikiREST["GPIOs"]["P19"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 432 | WIZwikiREST["GPIOs"]["P19"].cb_action = p19_set; |
MidnightCow | 1:728e5b5c8dae | 433 | WIZwikiREST["GPIOs"]["P20"] = GP20.read(); |
MidnightCow | 1:728e5b5c8dae | 434 | WIZwikiREST["GPIOs"]["P20"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 435 | WIZwikiREST["GPIOs"]["P20"].cb_action = p20_set; |
MidnightCow | 1:728e5b5c8dae | 436 | WIZwikiREST["GPIOs"]["P21"] = GP21.read(); |
MidnightCow | 1:728e5b5c8dae | 437 | WIZwikiREST["GPIOs"]["P21"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 438 | WIZwikiREST["GPIOs"]["P21"].cb_action = p21_set; |
MidnightCow | 1:728e5b5c8dae | 439 | WIZwikiREST["GPIOs"]["P22"] = GP22.read(); |
MidnightCow | 1:728e5b5c8dae | 440 | WIZwikiREST["GPIOs"]["P22"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 441 | WIZwikiREST["GPIOs"]["P22"].cb_action = p22_set; |
MidnightCow | 1:728e5b5c8dae | 442 | |
MidnightCow | 1:728e5b5c8dae | 443 | WIZwikiREST["GPIOs"]["P23"] = GP23.read(); |
MidnightCow | 1:728e5b5c8dae | 444 | WIZwikiREST["GPIOs"]["P23"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 445 | WIZwikiREST["GPIOs"]["P23"].cb_action = p23_set; |
MidnightCow | 1:728e5b5c8dae | 446 | WIZwikiREST["GPIOs"]["P24"] = GP24.read(); |
MidnightCow | 1:728e5b5c8dae | 447 | WIZwikiREST["GPIOs"]["P24"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 448 | WIZwikiREST["GPIOs"]["P24"].cb_action = p24_set; |
MidnightCow | 1:728e5b5c8dae | 449 | WIZwikiREST["GPIOs"]["P25"] = GP25.read(); |
MidnightCow | 1:728e5b5c8dae | 450 | WIZwikiREST["GPIOs"]["P25"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 451 | WIZwikiREST["GPIOs"]["P25"].cb_action = p25_set; |
MidnightCow | 1:728e5b5c8dae | 452 | WIZwikiREST["GPIOs"]["P26"] = GP26.read(); |
MidnightCow | 1:728e5b5c8dae | 453 | WIZwikiREST["GPIOs"]["P26"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 454 | WIZwikiREST["GPIOs"]["P26"].cb_action = p26_set; |
MidnightCow | 1:728e5b5c8dae | 455 | WIZwikiREST["GPIOs"]["P27"] = GP27.read(); |
MidnightCow | 1:728e5b5c8dae | 456 | WIZwikiREST["GPIOs"]["P27"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 457 | WIZwikiREST["GPIOs"]["P27"].cb_action = p27_set; |
MidnightCow | 1:728e5b5c8dae | 458 | WIZwikiREST["GPIOs"]["P28"] = GP28.read(); |
MidnightCow | 1:728e5b5c8dae | 459 | WIZwikiREST["GPIOs"]["P28"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 460 | WIZwikiREST["GPIOs"]["P28"].cb_action = p28_set; |
MidnightCow | 1:728e5b5c8dae | 461 | WIZwikiREST["GPIOs"]["P29"] = GP29.read(); |
MidnightCow | 1:728e5b5c8dae | 462 | WIZwikiREST["GPIOs"]["P29"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 463 | WIZwikiREST["GPIOs"]["P29"].cb_action = p29_set; |
joon874 | 2:ca36ecca24c2 | 464 | /* |
MidnightCow | 1:728e5b5c8dae | 465 | WIZwikiREST["GPIOs"]["P30"] = GP30.read(); |
MidnightCow | 1:728e5b5c8dae | 466 | WIZwikiREST["GPIOs"]["P30"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 467 | WIZwikiREST["GPIOs"]["P30"].cb_action = p30_set; |
MidnightCow | 1:728e5b5c8dae | 468 | WIZwikiREST["GPIOs"]["P31"] = GP31.read(); |
MidnightCow | 1:728e5b5c8dae | 469 | WIZwikiREST["GPIOs"]["P31"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 470 | WIZwikiREST["GPIOs"]["P31"].cb_action = p31_set; |
MidnightCow | 1:728e5b5c8dae | 471 | WIZwikiREST["GPIOs"]["P32"] = GP32.read(); |
MidnightCow | 1:728e5b5c8dae | 472 | WIZwikiREST["GPIOs"]["P32"].accessible = true; |
MidnightCow | 1:728e5b5c8dae | 473 | WIZwikiREST["GPIOs"]["P32"].cb_action = p32_set; |
joon874 | 2:ca36ecca24c2 | 474 | */ |
MidnightCow | 1:728e5b5c8dae | 475 | debug_info(); |
joon874 | 0:5886f525a4ad | 476 | } |