[zumo-cc3200/zumo-cc3200.git] / src / Energia / libraries / ZumoCC3200 / examples / Multicast / apLoop.ino
1 /*
2 * ======== apLoop ========
3 * This sketch waits on either a button press or a
4 *
5 * The name and password of the network and the port number of the server
6 * (always at IP address 192.168.1.1) can be changed below.
7 */
9 #include <WiFi.h>
10 #include <Pushbutton.h>
11 #include <ti/sysbios/knl/Task.h>
12 #include "MCP.h"
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
18 /* name of the network and its password */
19 char ssid[] = "zumo-multicast";
20 char wifipw[] = "password";
22 /* shared network */
23 char netID[] = "TINK-NET";
25 /* zumo command port */
26 #define CMD_PORT 8080
28 /* IMU data port */
29 #define DATA_PORT 6000
31 IPAddress broadcastIP(192,168,1,255);
33 long signalStrength = 0;
35 /*
36 * ======== apSetup ========
37 */
38 void apSetup()
39 {
40 Serial.begin(9600);
42 /* set priority of this task to be lower than other tasks */
43 //Task_setPri(Task_self(), 1);
45 // attempt to connect to Wifi network:
46 Serial.print("Connecting to target: ");
47 // print the network name (SSID);
48 Serial.println(netID);
49 // Connect to target zumo
50 //WiFi.begin(ssid, wifipw);
51 WiFi.begin(netID);
52 while ( WiFi.status() != WL_CONNECTED) {
53 // print dots while we wait to connect
54 Serial.print(".");
55 delay(300);
56 }
58 Serial.println("Connected");
59 Serial.println("Waiting for an ip address");
61 while (WiFi.localIP() == INADDR_NONE) {
62 // print dots while we wait for an ip addresss
63 Serial.print(".");
64 delay(300);
65 }
67 Serial.println("\nIP Address obtained");
68 printWifiStatus();
70 MCP_init();
72 }
74 /*
75 * ======== apLoop ========
76 */
78 void apLoop()
79 {
80 signalStrength = WiFi.RSSI();
81 Serial.println(signalStrength);
82 static char buf[16] = {0};
83 snprintf(buf, sizeof(buf), "%d", signalStrength);
84 MCP_printf(buf);
86 delay(1000);
87 }
89 void printWifiStatus() {
90 // print the SSID of the network you're attached to:
91 Serial.print("SSID: ");
92 Serial.println(WiFi.SSID());
94 // print your WiFi IP address:
95 IPAddress ip = WiFi.localIP();
96 Serial.print("IP Address: ");
97 Serial.println(ip);
99 // print the received signal strength:
100 long rssi = WiFi.RSSI();
101 Serial.print("signal strength (RSSI):");
102 Serial.print(rssi);
103 Serial.println(" dBm");
104 }