Hello everyone!
I WILL DO RESEARCH, SEND DATA FROM NODE COORDINATOR THAT CONTAINS (UNO ARDUINO SHIELD + WIFI + XBee S2).
MY QUESTION HOW DO DATA TRANSFER FROM NODE COORDINATOR TO computer connected to WIFI NETWORK USING ACCESS POINT
-THANKS-
SEND DATA USING CC3000 WIFI SHIELD
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: SEND DATA USING CC3000 WIFI SHIELD
You will need a server application on your computer using either TCP- or UDP-based socket communications. You connect to that server using the CC3000 library, and send your data.
If you don't know what any of this means, you will need to find someone who knows how to implement a server application on your computer. Once you have that, sending data from the CC3000 is fairly easy.
If you don't know what any of this means, you will need to find someone who knows how to implement a server application on your computer. Once you have that, sending data from the CC3000 is fairly easy.
- mifta
- Posts: 9
- Joined: Wed Feb 18, 2015 1:02 am
Re: SEND DATA USING CC3000 WIFI SHIELD
okay , my arduino connected to the access point using the wifi network , and on the other hand there is a computer that I functioned as a server , display data using visual basic application .
I 've been using the library in order to use the CC3000 wifi shield .
-Thanks-
I 've been using the library in order to use the CC3000 wifi shield .
-Thanks-
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: SEND DATA USING CC3000 WIFI SHIELD
Have a look at this. It should be enough to get you started:
Code: Select all
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIVIDER); // you can change this clock speed
#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters!
#define WLAN_PASS "myPassword"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Hello, CC3000!\n"));
Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
/* Initialise the module */
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
// Optional SSID scan
// listSSIDResults();
Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
/* Wait for DHCP to complete */
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
//I'm assuming that the server address is 192.168.1.123
uint32_t ip = 192+ (168*256) + (1 * 65536L) + (123 * 16777216L);
//I'm assuming that the server port is 5678
uint16_t port = 5678;
//Use whatever sort of data buffer you want. Doesn't have to be a string
char dataBuffer[] = "my data string";
//If you use a struct type for your dataBuffer, you can use the sizeof() function to get the buffer length
uint16_t bufferLength = strlen(dataBuffer);
//Print out the server address to make sure you've got it right.
cc3000.printIPdotsRev(ip);
//I'm assuming that your server is listening on TCP
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, port);
if (www.connected())
{
www.write(dataBuffer, bufferLength);
}
else
{
Serial.println(F("Connection failed"));
return;
}
www.close();
}
void loop()
{
delay(1000);
}
- mifta
- Posts: 9
- Joined: Wed Feb 18, 2015 1:02 am
Re: SEND DATA USING CC3000 WIFI SHIELD
oke terimakasih, BANNED saya coba pada arduino.
tetapi connecting ke IP yang dituju tidak bisa.
//I'm assuming that the server address is 192.168.1.123
uint32_t ip = 192+ (168*256) + (1 * 65536L) + (123 * 16777216L);
//I'm assuming that the server port is 5678
uint16_t port = 5678;
yang keluar ada serial monitor seperti ini.
tetapi connecting ke IP yang dituju tidak bisa.
//I'm assuming that the server address is 192.168.1.123
uint32_t ip = 192+ (168*256) + (1 * 65536L) + (123 * 16777216L);
//I'm assuming that the server port is 5678
uint16_t port = 5678;
yang keluar ada serial monitor seperti ini.
- Attachments
-
- serial monitor.jpg (54.09 KiB) Viewed 828 times
- Franklin97355
- Posts: 23940
- Joined: Mon Apr 21, 2008 2:33 pm
Re: SEND DATA USING CC3000 WIFI SHIELD
That form of IP usually means the windows box could not get an IP so assigned the "default" Make sure your router can act as a DNS server or use a valid DNS server IP like 8.8.8.8 (Google)
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: SEND DATA USING CC3000 WIFI SHIELD
Oops. I made a mistake. The IP address is backwards.
What is the address and port of your server?
What is the address and port of your server?
- mifta
- Posts: 9
- Joined: Wed Feb 18, 2015 1:02 am
Re: SEND DATA USING CC3000 WIFI SHIELD
yes sir, its ip reversed. My server IP 192.168.1.11 port 1111 on the server that I receive data using visual basic
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: SEND DATA USING CC3000 WIFI SHIELD
Right. Try this:
Code: Select all
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIVIDER); // you can change this clock speed
#define WLAN_SSID "myNetwork" // cannot be longer than 32 characters!
#define WLAN_PASS "myPassword"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Hello, CC3000!\n"));
Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
/* Initialise the module */
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
// Optional SSID scan
// listSSIDResults();
Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
/* Wait for DHCP to complete */
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
//I'm assuming that the server address is 192.168.1.111
uint32_t ip = 111 + (1*256) + (168 * 65536L) + (192 * 16777216L);
//I'm assuming that the server port is 1111
uint16_t port = 1111;
//Use whatever sort of data buffer you want. Doesn't have to be a string
char dataBuffer[] = "my data string";
//If you use a struct type for your dataBuffer, you can use the sizeof() function to get the buffer length
uint16_t bufferLength = strlen(dataBuffer);
//Print out the server address to make sure you've got it right.
cc3000.printIPdotsRev(ip);
//I'm assuming that your server is listening on TCP
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, port);
if (www.connected())
{
www.write(dataBuffer, bufferLength);
}
else
{
Serial.println(F("Connection failed"));
return;
}
www.close();
}
void loop()
{
delay(1000);
}
- mifta
- Posts: 9
- Joined: Wed Feb 18, 2015 1:02 am
Re: SEND DATA USING CC3000 WIFI SHIELD
sir, like where do I send that data in the variable?
- Attachments
-
- Capture.PNG (6.57 KiB) Viewed 670 times
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: SEND DATA USING CC3000 WIFI SHIELD
Code: Select all
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, port);
if (www.connected())
{
www.write(dataBuffer, bufferLength);
}
- mifta
- Posts: 9
- Joined: Wed Feb 18, 2015 1:02 am
Re: SEND DATA USING CC3000 WIFI SHIELD
sir, I have a problem.
I have a coordinator node and receiving data from the XBee client by using a string variable. The coordinator further also use wifi shield for the CC3000 by sending the data to the server computer by using wifi network.
here I show my program. and I want to ask, using the wifi network data is transmitted using a variable uint16_t (unsigned short), sir, how that data can be sent?
thanks
I have a coordinator node and receiving data from the XBee client by using a string variable. The coordinator further also use wifi shield for the CC3000 by sending the data to the server computer by using wifi network.
here I show my program. and I want to ask, using the wifi network data is transmitted using a variable uint16_t (unsigned short), sir, how that data can be sent?
thanks
Code: Select all
void connectingServer()
{
uint32_t ip = 11 + (1 * 256) + (168 * 65536L) + (192 * 16777216L);
uint16_t port = 1001;
cc3000.printIPdotsRev(ip);
Adafruit_CC3000_Client request = cc3000.connectUDP(ip, port);
if (request.connected())
{
Serial.println("Connected");
while (Serial.available()>0)
{
char entry_data = (char)Serial.read();
buff += entry_data;
uint16_t bufferLength = strlen(buff);
request.write(buff, bufferLength);
}
}
else
{
Serial.println(F("Connection failed"));
return;
}
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: SEND DATA USING CC3000 WIFI SHIELD
First of all, you don't want to do this:
That will send the entire string each time you read a character. So you will get multiple iterations of the same string. For example: "t", "te", "tes", "test"
Instead, don't send the string until you're done reading:.
Also, you don't want to send buff, as this is a String object. You want to send the string contents of buff. For that, you use the c_str() method.
Finally, if you want to send the string length, you can send it either as a binary or as ascii. To send as binary, use the write statement. To send as ascii, use the print statement
Finally, always use the reserve method on String objects. This reserves memory for the String and prevents memory fragmentation:
You can read more on memory fragmentation here:
https://learn.adafruit.com/memories-of-an-arduino
Code: Select all
while (Serial.available()>0)
{
char entry_data = (char)Serial.read();
buff += entry_data;
uint16_t bufferLength = strlen(buff);
request.write(buff, bufferLength);
}
Instead, don't send the string until you're done reading:.
Also, you don't want to send buff, as this is a String object. You want to send the string contents of buff. For that, you use the c_str() method.
Finally, if you want to send the string length, you can send it either as a binary or as ascii. To send as binary, use the write statement. To send as ascii, use the print statement
Code: Select all
buff = "";
while (Serial.available()>0)
{
char entry_data = (char)Serial.read();
buff += entry_data;
}
uint16_t bufferLength = strlen(buff);
request.write(&bufferLength, sizeof(uint16_t)); //send buffer length as binary
// request.print(bufferLength); //alternate - send buffer length as ascii
request.write(buff.c_str(), bufferLength);
}
Code: Select all
String buff;
void setup()
{
. . . etc . . .
buff.reserve(64); // pick a number for this that's slightly larger than the largest String length you ever expect to need
. . . etc . . .
}
https://learn.adafruit.com/memories-of-an-arduino
- mifta
- Posts: 9
- Joined: Wed Feb 18, 2015 1:02 am
Re: SEND DATA USING CC3000 WIFI SHIELD
thanks you for replay, sir.
sorry this program can't be executed. i do not know why.
sorry this program can't be executed. i do not know why.
- Attachments
-
- forum.JPG (94.93 KiB) Viewed 551 times
- mifta
- Posts: 9
- Joined: Wed Feb 18, 2015 1:02 am
Re: SEND DATA USING CC3000 WIFI SHIELD
this is my program, sir
Code: Select all
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIVIDER); // you can change this clock speed
#define WLAN_SSID "AP_SKRIPSI" // cannot be longer than 32 characters!
#define WLAN_PASS "password"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
//----------------------------------------------------------------------------------------------
//unsigned short unitId;
String buff;
int client;
boolean flag=false;
int i=0;
//----------------------------------------------------------------------------------------------
void setup(void)
{
Serial.begin(9600);
buff.reserve(64);
Serial.println(F("Hello, CC3000!\n"));
/* Initialise the module */
Serial.println(F("\nInitializing..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
// Optional SSID scan
// listSSIDResults();
Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected"));
/* Wait for DHCP to complete */
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100); // ToDo: Insert a DHCP timeout!
}
while (!displayConnectionDetails())
{
delay(100);
}
connectingServer();
}
//-----------------------------------------------------------------------------------
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Address : ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask : ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway : ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCP server : ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNS server : ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}
void connectingServer()
{
uint32_t ip = 11 + (1 * 256) + (168 * 65536L) + (192 * 16777216L);
uint16_t port = 1001;
cc3000.printIPdotsRev(ip);
Adafruit_CC3000_Client request = cc3000.connectUDP(ip, port);
if (request.connected())
{
Serial.println("Connected");
buff = "";
while (Serial.available()>0)
{
char entry_data = (char)Serial.read();
buff += entry_data;
uint16_t bufferLength = strlen(buff);
request.write(&bufferLength, sizeof(uint16_t));
request.write(buff.c_str(), bufferLength);
}
}
else
{
Serial.println(F("Connection failed"));
return;
}
}
void loop()
{
}
Please be positive and constructive with your questions and comments.