Arduino mega2560+ seeeduino ethernet W5200 + iOS

Нет ответов
Jhonson
Offline
Зарегистрирован: 28.02.2014

Здравствуйте!

В программировании я новичек, поэтому не пинайте за глупости.

Прошу направить на путь истинный в решении моей проблемы.

Имеем:

Arduino mega 2560

Seeeduino Ethernet V2_0 W5200

Arduino Manager для iOS.

https://sites.google.com/site/fabboco/home/arduino-manager-for-iphone-ipad По ссылке есть описание софта и сами библиотеки. Я использую iOSController.h

iPad генерирует следующий скетч:

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <IOSController.h>

/* Start your code (defines) */
/* End your code */

/*
 *
 * Initialize the Ethernet server library
 */
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 

IPAddress ip(192,168,1,254);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,0,0);

EthernetServer server(8090);

/*
 *
 * Prototypes of IOSController's callbacks
 *
 *
 */
void doWork();
void doSync(char *variable);
void processIncomingMessages(char *variable, char *value);
void processOutgoingMessages();
void processAlarms(char *variable);
void deviceConnected();
void deviceDisconnected();

/*
 *
 * IOSController Library initialization
 *
 */
IOSController iosController(&server,&doWork,&doSync,&processIncomingMessages,&processOutgoingMessages,NULL,NULL);

/******* Start Global Variable for Widgets *******/
float A0;
float A1;
float A2;
float A3;
float A4;

/******* End Global Variable for Widgets *******/

void setup() {
  
  Serial.begin(9600);
  
  

  Ethernet.begin(mac, ip, subnet, gateway);  
  server.begin();

  /* Start your code (setup) */
  /* End your code */
}

void loop() {
  
  iosController.loop(500);
}

/**
*
*
* This function is called periodically and its equivalent to the standard loop() function
*
*/
void doWork() {



  /* Start your code (doWork) */
  /* End your code */
}

/**
*
*
* This function is called when the ios device connects and needs to initialize the position of switches and knobs
*
*/
void doSync (char *variable) {


  if(strcmp(variable,"Sw1")==0) {

    switchSw1SyncCallback();
  }

  if(strcmp(variable,"Sw2")==0) {

    switchSw2SyncCallback();
  }

  if(strcmp(variable,"Sw3")==0) {

    switchSw3SyncCallback();
  }

  if(strcmp(variable,"Sw4")==0) {

    switchSw4SyncCallback();
  }

  if(strcmp(variable,"Sw5")==0) {

    switchSw5SyncCallback();
  }


  /* Start your code (doSync) */
  /* End your code */
}

/**
*
*
* This function is called when a new message is received from the iOS device
*
*/
void processIncomingMessages(char *variable, char *value) {


  if(strcmp(variable,"Sw1")==0) {

    switchSw1Callback(atoi(value));
  }

  if(strcmp(variable,"Sw2")==0) {

    switchSw2Callback(atoi(value));
  }

  if(strcmp(variable,"Sw3")==0) {

    switchSw3Callback(atoi(value));
  }

  if(strcmp(variable,"Sw4")==0) {

    switchSw4Callback(atoi(value));
  }

  if(strcmp(variable,"Sw5")==0) {

    switchSw5Callback(atoi(value));
  }


  /* Start your code (processIncomingMessages) */
  /* End your code */
}

/**
*
*
* This function is called periodically and messages can be sent to the iOS device
*
*/
void processOutgoingMessages() {


  iosController.writeMessage("A0",A0);
  iosController.writeMessage("A1",A1);
  iosController.writeMessage("A2",A2);
  iosController.writeMessage("A3",A3);
  iosController.writeMessage("A4",A4);


  /* Start your code (processOutgoingMessages) */
  /* End your code */
}


/* Widgets synchronization callbacks */

void switchSw1SyncCallback() {

  /* Start your code (switchSw1SyncCallback) */

  //iosController.writeMessage("Sw1",Insert value here);

  /* End your code */

}

void switchSw2SyncCallback() {

  /* Start your code (switchSw2SyncCallback) */

  //iosController.writeMessage("Sw2",Insert value here);

  /* End your code */

}

void switchSw3SyncCallback() {

  /* Start your code (switchSw3SyncCallback) */

  //iosController.writeMessage("Sw3",Insert value here);

  /* End your code */

}

void switchSw4SyncCallback() {

  /* Start your code (switchSw4SyncCallback) */

  //iosController.writeMessage("Sw4",Insert value here);

  /* End your code */

}

void switchSw5SyncCallback() {

  /* Start your code (switchSw5SyncCallback) */

  //iosController.writeMessage("Sw5",Insert value here);

  /* End your code */

}


/* Widgets operations callbacks */

void switchSw1Callback(boolean on) {

  /* Start your code (switchSw1Callback) */
  /* End your code */
}

void switchSw2Callback(boolean on) {

  /* Start your code (switchSw2Callback) */
  /* End your code */
}

void switchSw3Callback(boolean on) {

  /* Start your code (switchSw3Callback) */
  /* End your code */
}

void switchSw4Callback(boolean on) {

  /* Start your code (switchSw4Callback) */
  /* End your code */
}

void switchSw5Callback(boolean on) {

  /* Start your code (switchSw5Callback) */
  /* End your code */
}



/**** User Functions *****/

/* Start your code (User Functions) */
/* End your code */

Но  W5200 не работает со стандартной библиотекой, а работает со своей  EthernetV2_0.h

Поэтому (насколько я понимаю) в коде скетча необходимо заменить Ethernet.h на EthernetV2_0.h

Теперь при компиляции возникает ошибка со ссылкой на библиотеку iOSController.h код которой приведу ниже:

/*
*
 * IOSController library (“The Software”) and the related documentation (“The Documentation”) are supplied to you 
 * by the Author in consideration of your agreement to the following terms, and your use or installation of The Software and the use of The Documentation 
 * constitutes acceptance of these terms.  
 * If you do not agree with these terms, please do not use or install The Software.
 * The Author grants you a personal, non-exclusive license, under author's copyrights in this original software, to use The Software. 
 * Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by the Author, including but not limited to any 
 * patent rights that may be infringed by your derivative works or by other works in which The Software may be incorporated.
 * The Software and the Documentation are provided by the Author on an "AS IS" basis.  THE AUTHOR MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT 
 * LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE SOFTWARE OR ITS USE AND OPERATION 
 * ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, 
 * REPRODUCTION AND MODIFICATION OF THE SOFTWARE AND OR OF THE DOCUMENTATION, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 
 * STRICT LIABILITY OR OTHERWISE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * Author: Fabrizio Boco - fabboco@gmail.com
 *
 * Version: 2.0.1
 *
 * All rights reserved
 *
 */

#ifndef IOSController_h
#define IOSController_h

#define SD_SUPPORT        // uncomment to enable support for SD Widget - Download only
#define ALARMS_SUPPORT    // uncomment to enable support for Alarm Widget
#define SDLOGGEDATAGRAPH_SUPPORT    // uncomment to enable support for Logged Data Widget
//#define DEBUG           // uncomment to unable debugging - You should not need it !

#include <Ethernet.h>

#ifdef SD_SUPPORT 
	#include <SD.h>
#endif 

#ifdef SDLOGGEDATAGRAPH_SUPPORT 
	#include <SD.h>
#endif 


#ifdef ALARMS_SUPPORT

typedef struct  {
	char 			id[12];  // First character of id is always A
	unsigned long 	time;
	bool			repeat;
} alarm;

#endif

#define VARIABLELEN 14
#define VALUELEN 14

class IOSController {

private:
char			_variable[VARIABLELEN+1];
char 	   		_value[VALUELEN+1];
bool	   		_var;
int       		_idx;
EthernetServer 	*_server;
EthernetClient  _client;

#ifdef ALARMS_SUPPORT
EthernetUDP 	_udp;
IPAddress 		_timeServerAddress;  // NTP Server Address
bool			_sendNtpRequest;
byte 			_packetBuffer[48]; 	// buffer to hold incoming and outgoing packets 
unsigned long   _fireAlarmDelay;
unsigned long	_startTime;
#endif

/**
Pointer to the function where to put code in place of loop()
**/
void (*_doWork)(void); 

/*
Pointer to the function where Switches, Knobs and Leds are syncronized
*/
void (*_doSync)(char *variable);

/*
Pointer to the function where incoming messages are processed
*
* variable
*
* value
*
*/
void (*_processIncomingMessages)(char *variable, char *value);

/*
Pointer to the function where outgoing messages are processed
*
*/
void (*_processOutgoingMessages)(void);

#ifdef ALARMS_SUPPORT
/*
Pointer to the function where alerts are processed
*
*/
void (*_processAlarms)(char *alarm);
#endif

/*
Pointer to the function called when a device connects to Arduino
*
*/
void (*_deviceConnected)(void);

/*
Pointer to the function called when a device disconnects from Arduino
*
*/
void (*_deviceDisconnected)(void);

void readVariable(void);

#ifdef ALARMS_SUPPORT

unsigned long sendNTPpacket(IPAddress& address, EthernetUDP udp);
void breakTime(unsigned long time, int *seconds, int *minutes, int *hours, int *Wday, long *Year, int *Month, int *Day);

void syncTime();
void readTime();

void inizializeAlarms();
void checkAndFireAlarms(unsigned long delay);
void createUpdateAlarm(char *id, unsigned long time, bool repeat);
void removeAlarm(char *id);
	
#endif

public:

#ifdef ALARMS_SUPPORT
	IOSController(EthernetServer *server, 
								  void (*doWork)(void), void (*doSync)(char *variable), 
								  void (*processIncomingMessages)(char *variable, char *value),
								  void (*processOutgoingMessages)(void),
								  void (*processAlarms)(char *alarm),
								  void (*deviceConnected)(void),
								  void (*deviceDisconnected)(void));
#endif

	IOSController(EthernetServer *server, 
								  void (*doWork)(void), void (*doSync)(char *variable), 
								  void (*processIncomingMessages)(char *variable, char *value),
								  void (*processOutgoingMessages)(void),
								  void (*deviceConnected)(void),
								  void (*deviceDisconnected)(void));
								  		  
	void loop();
	void loop(unsigned long delay);
	void writeMessage(char *variable, float value);
	void writeTxtMessage(char *variable, char *value);
		
	void log(char *msg);
	void log(int msg);

	void logLn(char *msg);
	void logLn(int msg);
	void logLn(long msg);
	void logLn(unsigned long msg);

	void temporaryDigitalWrite(uint8_t pin, uint8_t value, unsigned long ms);
	
	void setNTPServerAddress(IPAddress address);	
	
#ifdef ALARMS_SUPPORT 	
	unsigned long now();
#ifdef DEBUG
	void dumpAlarms();
  	void printTime(unsigned long time);
#endif 
#endif 

#ifdef SDLOGGEDATAGRAPH_SUPPORT

	void sdLogLabels(char *variable, char *label1);
	void sdLogLabels(char *variable, char *label1, char *label2);
	void sdLogLabels(char *variable, char *label1, char *label2, char *label3);
	void sdLogLabels(char *variable, char *label1, char *label2, char *label3, char *label4);
	void sdLogLabels(char *variable, char *label1, char *label2, char *label3, char *label4, char *label5);

	void sdLog(char *variable, unsigned long time, float v1);
	void sdLog(char *variable, unsigned long time, float v1, float v2);
	void sdLog(char *variable, unsigned long time, float v1, float v2, float v3);
	void sdLog(char *variable, unsigned long time, float v1, float v2, float v3, float v4);
	void sdLog(char *variable, unsigned long time, float v1, float v2, float v3, float v4, float v5);
	
	void sdSendLogData(char *variable);
	
#endif	

};
#endif

33 строка тоже ссылается на стандартную библиотеку Ethernet, поэтому переименуем в EthernetV2_0.h

Теперь ошибок компиляции не возникает и скетч заливается в плату.

После заливки проверяю работоспособность платы командой ping. плата отвечает.

Но iPad почему то не подключается по указанному адресу.

Для проверки работоспособности заливаю стандартный пример web сервера из поставки seeeduino 

iPad успешно подключается монитор порта транслирует сообщения полученные от Arduino Manager.