extern "C" {
#include "uip.h"
}
#include <WiShield.h>
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {169, 254, 209, 10}; // IP address of WiShield
unsigned char gateway_ip[] = {192, 168, 1, 1}; // router or gateway IP address
unsigned char subnet_mask[] = {255, 255, 255, 0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"SSID"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"password"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
int potValue = 0;
void setup()
{
Serial.begin(57600);
WiFi.init();
}
void loop()
{
potValue = analogRead(0);
WiFi.run();
}
extern "C"
{
void udpapp_init(void)
{
uip_ipaddr_t addr;
struct uip_udp_conn *c;
uip_ipaddr(&addr, 255, 255, 255, 255);
c = uip_udp_new(&addr, HTONS(1234));
if(c != NULL) {
uip_udp_bind(c, HTONS(1234));
}
}
static void send_data(void)
{
char str[5];
sprintf(str, "%d", (potValue-5));
Serial.println((const char*)str);
memcpy(uip_appdata, str, 5);
//memcpy(uip_appdata, potValue, 2); <--error
uip_send(uip_appdata, 5);
}
void udpapp_appcall(void)
{
//send data on the poll timer timeout
if(0 != uip_poll()) {
send_data();
}
}
void dummy_app_appcall(void)
{
}
}
extern "C" {
#include "uip.h"
}
#include <WiShield.h>
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {169, 254, 209, 20}; // IP address of WiShield
unsigned char gateway_ip[] = {192, 168, 1, 1}; // router or gateway IP address
unsigned char subnet_mask[] = {255, 255, 255, 0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"SSID"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"password"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
int ledValue = 0;
void setup()
{
Serial.begin(57600);
WiFi.init();
}
void loop()
{
analogWrite(2, ledValue);
WiFi.run();
}
extern "C"
{
void udpapp_init(void)
{
uip_ipaddr_t addr;
struct uip_udp_conn *c;
uip_ipaddr(&addr, 255, 255, 255, 255);
c = uip_udp_new(&addr, HTONS(1234));
if(c != NULL) {
uip_udp_bind(c, HTONS(1234));
}
}
void udpapp_appcall(void)
{
//receive incoming data
if(0 != uip_newdata()) {
char str[5];
memcpy(str, uip_appdata, 5);
//memcpy(ledValue, uip_appdata, 2); <--error
ledValue= atoi((const char*)str);
Serial.println(ledValue);
}
}
void dummy_app_appcall(void)
{
}
}
void setup()
{
Serial.begin(57600);
int first;
int second;
unsigned char buffer[32];
// small integer test case
first = 8;
second = 0;
memset(buffer, 0, 32 * sizeof(unsigned char));
// your send case
memcpy(buffer, &first, 2);
// your receive case
memcpy(&second, buffer, 2);
Serial.print("first : ");
Serial.println(first, DEC);
Serial.print("second : ");
Serial.println(second, DEC);
Serial.print("buffer[0]: ");
Serial.println(buffer[0], DEC);
Serial.print("buffer[1]: ");
Serial.println(buffer[1], DEC);
// larger integer test case
first = 888;
second = 0;
memset(buffer, 0, 32 * sizeof(unsigned char));
// your send case
memcpy(buffer, &first, 2);
// your receive case
memcpy(&second, buffer, 2);
Serial.print("first : ");
Serial.println(first, DEC);
Serial.print("second : ");
Serial.println(second, DEC);
Serial.print("buffer[0]: ");
Serial.println(buffer[0], DEC);
Serial.print("buffer[1]: ");
Serial.println(buffer[1], DEC);
}
void loop()
{
}
extern "C" {
#include "uip.h"
}
#include <WiShield.h>
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {169, 254, 209, 10}; // IP address of WiShield
unsigned char gateway_ip[] = {192, 168, 1, 1}; // router or gateway IP address
unsigned char subnet_mask[] = {255, 255, 255, 0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"horsies"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"password"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
int sensors[10];
void setup()
{
Serial.begin(57600);
WiFi.init();
}
void loop()
{
for(int i = 0; i < 10; i++){
sensors[i] = map(analogRead(i), 0, 1023, 0, 255);
}
WiFi.run();
}
extern "C"
{
void udpapp_init(void)
{
uip_ipaddr_t addr;
struct uip_udp_conn *c;
uip_ipaddr(&addr, 255, 255, 255, 255);
c = uip_udp_new(&addr, HTONS(1234));
if(c != NULL) {
uip_udp_bind(c, HTONS(1234));
}
}
static void send_data(void)
{
for(int i = 0; i < 3; i++){
char str[3];
sprintf(str, "%i%i", i, sensors[i]);
Serial.println((const char*)str);
memcpy(uip_appdata, str, strlen(str));
uip_send(uip_appdata, strlen(str));
}
}
void udpapp_appcall(void)
{
//send data on the poll timer timeout
if(0 != uip_poll()) {
send_data();
}
}
void dummy_app_appcall(void)
{
}
}
extern "C" {
#include "uip.h"
}
#include <WiShield.h>
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {169, 254, 209, 20}; // IP address of WiShield
unsigned char gateway_ip[] = {192, 168, 1, 1}; // router or gateway IP address
unsigned char subnet_mask[] = {255, 255, 255, 0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"horsies"}; // max 32 bytes
unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"password"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
int motors[10];
void setup()
{
Serial.begin(57600);
WiFi.init();
}
void loop()
{
for(int i = 0; i < 10; i++){
analogWrite(i, motors[i]);
}
WiFi.run();
}
extern "C"
{
void udpapp_init(void)
{
uip_ipaddr_t addr;
struct uip_udp_conn *c;
uip_ipaddr(&addr, 255, 255, 255, 255);
c = uip_udp_new(&addr, HTONS(1234));
if(c != NULL) {
uip_udp_bind(c, HTONS(1234));
}
}
void udpapp_appcall(void)
{
if(0 != uip_newdata()){
char str[3];
memcpy(str, uip_appdata, strlen(str));
int index = str[0];
str[0] = str[1];
str[1] = str[2];
str[2] = NULL;
motors[index]= atoi((const char*)str);
Serial.println(motors[index]);
}
}
void dummy_app_appcall(void)
{
}
}
Return to Sketches and Applications
Users browsing this forum: No registered users and 1 guest