Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: cc3000_hostdriver_mbedsocket mbed
main.cpp
00001 /* 00002 CC3000 OSC message tranceiver(Sender/Receiver) 00003 00004 Sparkfun CC3000 WiFi Shield meets mbed! 00005 00006 This program supports the following mbed boards with Sparkfun CC3000 Sheild. 00007 '#define' switches board.(refer to source code) 00008 (1)FRDM-KL25Z (K25Z) 00009 (2)ST Nucleo F401RE (STM32F401) 00010 (3)ST Nucleo F030R8 (STM32F030) 00011 (4)LPCXpresso1549 (LPC1549) 00012 (5)Seeduino-Arch-Pro (ARCH_PRO) 00013 (6)FRDM-K64F (K64F) 00014 00015 Please push RESET button on CC3000 WiFi Shield to start the program. 00016 00017 reference: 00018 https://www.sparkfun.com/products/12071 for CC300 Shield 00019 http://opensoundcontrol.org/introduction-osc for OSC(Open Sound Control) 00020 00021 date: 2014/9/3 00022 added supporting FRDM-K64F by: xshige 00023 00024 date: 2014/8/31 00025 written by: xshige 00026 00027 console out sample: 00028 ========================================== 00029 CC3000 OSC receive&send demo. 00030 IP address: 192.168.0.3 00031 This OSC msg sent: 00032 /1/fader1 ,f 0.000000 00033 to: 192.168.0.11 00034 ------------------- 00035 This OSC msg sent: 00036 /1/fader5 ,f 0.172000 00037 to: 192.168.0.11 00038 ------------------- 00039 00040 Wait for OSC message... 00041 00042 This OSC msg sent: 00043 /1/fader5 ,f 0.127000 00044 to: 192.168.0.11 00045 ------------------- 00046 00047 Wait for OSC message... 00048 00049 incomming OSC msg: 00050 /1/fader2 ,f 0.761603 00051 Received packet from: 192.168.0.2 00052 ------------------- 00053 This OSC msg sent: 00054 /1/fader5 ,f 0.711000 00055 to: 192.168.0.2 00056 ------------------- 00057 00058 Wait for OSC message... 00059 00060 incomming OSC msg: 00061 /1/fader2 ,f 0.767932 00062 Received packet from: 192.168.0.2 00063 ------------------- 00064 This OSC msg sent: 00065 /1/fader5 ,f 0.286000 00066 to: 192.168.0.2 00067 ------------------- 00068 00069 Wait for OSC message... 00070 00071 ========================================== 00072 */ 00073 00074 #include "mbed.h" 00075 #include "cc3000.h" 00076 00077 #include "UDPSocket.h" 00078 00079 // define board you like (KL25Z, LPC1549, STM32F401, STM32F030 ...) 00080 //#define KL25Z 00081 //#define STM32F401 00082 //#define STM32F030 00083 //#define LPC1549 00084 //#define ARCH_PRO 00085 #define K64F 00086 00087 // define SSID, PASSWORD you like 00088 #define SSID "sssid" 00089 #define PASSWORD "password" 00090 00091 using namespace mbed_cc3000; 00092 00093 /* cc3000 module declaration specific for user's board. */ 00094 #if defined(KL25Z) 00095 // for KL25Z 00096 cc3000 wifi(PTD4, PTC9, PTD0, SPI(PTD2, PTD3, PTD1), SSID, PASSWORD, WPA2, false); 00097 Serial pc(USBTX, USBRX); 00098 #endif 00099 #if defined(STM32F401) 00100 // for Nucleo STM32F401 00101 cc3000 wifi(PA_10, PA_8, PB_6, SPI(PA_7, PA_6, PA_5), SSID, PASSWORD, WPA2, false); 00102 // for Nucleo STM32F401 00103 Serial pc(SERIAL_TX, SERIAL_RX); 00104 #endif 00105 #if defined(STM32F030) 00106 // for Nucleo STM32F030 00107 cc3000 wifi(PA_10, PA_8, PB_6, SPI(PA_7, PA_6, PA_5), SSID, PASSWORD, WPA2, false); 00108 // for Nucleo STM32F030 00109 Serial pc(SERIAL_TX, SERIAL_RX); 00110 #endif 00111 #if defined(LPC1549) 00112 // for LPC1549 00113 cc3000 wifi(P0_29, P0_0, P0_27, SPI(P0_28, P0_12, P0_16), SSID, PASSWORD, WPA2, false); 00114 Serial pc(USBTX, USBRX); 00115 #endif 00116 #if defined(ARCH_PRO) 00117 // for Seeed Studio Arch Pro 00118 cc3000 wifi(P0_4, P2_5, P0_6, SPI(P0_9, P0_8, P0_7), SSID, PASSWORD, WPA2, false); 00119 Serial pc(USBTX, USBRX); 00120 #endif 00121 #if defined(K64F) 00122 // for FRDM-K64F 00123 cc3000 wifi(PTB9, PTC3, PTD0, SPI(PTD2, PTD3, PTD1), SSID, PASSWORD, WPA2, false); 00124 Serial pc(USBTX, USBRX); 00125 #endif 00126 00127 00128 // OSC related 00129 #include "OSCmsgCodec.h" 00130 00131 // set yout IP, PORTs 00132 #define REMOTE_IP "192.168.0.11" // (will be replaced after OSC msg received) 00133 #define OUTGOING_PORT 9000 00134 #define INCOMMING_PORT 8000 00135 00136 #define PACKET_SIZE 512 00137 #define RECBUF_SIZE 256 00138 #define PERIOD_BUZZER 10 00139 00140 union OSCarg msg[10], outmsg[10]; 00141 char recbuf[RECBUF_SIZE],buff[PACKET_SIZE],packet[PACKET_SIZE]; 00142 int len, tn; 00143 00144 char sendto_ip[16]; 00145 00146 int main() { 00147 // set initial IP to send 00148 strcpy(sendto_ip, REMOTE_IP); 00149 00150 pc.baud(115200); 00151 00152 printf("\n\nCC3000 OSC receive&send demo. \n"); 00153 wifi.init(); 00154 if (wifi.connect() == -1) { 00155 printf("Failed to connect. Please verify connection details and try again. \n"); 00156 printf("You should check your ssid, password.\n"); 00157 wait(60); 00158 } else { 00159 printf("IP address: %s \n", wifi.getIPAddress()); 00160 } 00161 00162 UDPSocket udpRec,udpSend; 00163 udpSend.init(); udpRec.bind(INCOMMING_PORT); 00164 00165 Endpoint target, client; 00166 target.set_address(REMOTE_IP, OUTGOING_PORT); 00167 00168 // send OSC message with random values (to touchOSC) 00169 // make OSC message for sending 00170 outmsg[0].address="/1/fader1"; 00171 outmsg[1].typeTag=",f"; 00172 outmsg[2].f= 0.0; 00173 memset(packet,0,sizeof(packet)); // clear send buff for OSC msg 00174 len=encOSCmsg(packet,outmsg); 00175 // send it 00176 target.set_address(sendto_ip, OUTGOING_PORT); 00177 udpSend.sendTo(target, packet, len); 00178 pc.printf("This OSC msg sent:\n%s %s %f\n", outmsg[0].address, outmsg[1].typeTag, outmsg[2].f); 00179 pc.printf("to: %s\n", sendto_ip); 00180 pc.printf("-------------------\n"); 00181 //wait_ms(10); 00182 00183 while (true) { 00184 #if 0 00185 // xy 00186 // send OSC message with random values (to touchOSC) 00187 // make OSC message for sending 00188 outmsg[0].address="/3/xy"; 00189 outmsg[1].typeTag=",ff"; 00190 outmsg[2].f = rand()%1000/1000.0; 00191 outmsg[3].f = rand()%1000/1000.0; 00192 memset(packet,0,sizeof(packet)); // clear send buff for OSC msg 00193 len=encOSCmsg(packet,outmsg); 00194 target.set_address(sendto_ip, OUTGOING_PORT); 00195 udpSend.sendTo(target, packet, len); 00196 //pc.printf("len:%d\n",len); 00197 pc.printf("This OSC msg sent:\n%s %s %f %f\n", outmsg[0].address, outmsg[1].typeTag, outmsg[2].f, outmsg[3].f); 00198 pc.printf("to: %s\n", sendto_ip); 00199 pc.printf("-------------------\n"); 00200 //wait_ms(10); 00201 #else 00202 // fader 00203 // send OSC message with random values (to touchOSC) 00204 // make OSC message for sending 00205 outmsg[0].address="/1/fader5"; 00206 outmsg[1].typeTag=",f"; 00207 outmsg[2].f= rand()%1000/1000.0; 00208 memset(packet,0,sizeof(packet)); // clear send buff for OSC msg 00209 len=encOSCmsg(packet,outmsg); 00210 // send it 00211 target.set_address(sendto_ip, OUTGOING_PORT); 00212 udpSend.sendTo(target, packet, len); 00213 //pc.printf("len:%d\n",len); 00214 pc.printf("This OSC msg sent:\n%s %s %f\n", outmsg[0].address, outmsg[1].typeTag, outmsg[2].f); 00215 pc.printf("to: %s\n", sendto_ip); 00216 pc.printf("-------------------\n"); 00217 //wait_ms(10); 00218 #endif 00219 00220 // receive OSC message 00221 printf("\nWait for OSC message...\n\n"); 00222 int n = udpRec.receiveFrom(client, recbuf, sizeof(recbuf)); 00223 if (n >= 0) { 00224 decOSCmsg(recbuf, msg); 00225 pc.printf("incomming OSC msg:\n%s %s", msg[0].address, msg[1].typeTag); 00226 for(int m=0; m < (strlen(msg[1].typeTag)-1); m++) { 00227 if (msg[1].typeTag[m+1]=='f') pc.printf(" %f",msg[m+2].f); 00228 if (msg[1].typeTag[m+1]=='i') pc.printf(" %d",msg[m+2].i); 00229 } 00230 pc.printf("\n"); 00231 printf("Received packet from: %s \n", client.get_address()); 00232 printf("-------------------\n"); 00233 // change IP to send 00234 strcpy(sendto_ip, client.get_address()); 00235 //wait_ms(10); 00236 }; 00237 } // while (true) 00238 }
Generated on Fri Aug 5 2022 04:31:11 by
1.7.2