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