connect HLK-RM04 to arduino uno (or mega)
when went reply existing thread "the system" suggested start new thread 1 on 120 days without response. trying accomplish:
getting rm04 send email on wifi on trigger event arduino card.
i person can't seem rm04 respond in way examples in chunlinhan/wifirm04 library. i have read every post on forum concerning , many others. got stopped @ "serial1" error.
i have used code below rayshobby.net (thanks ray). , have been able talk rm04 , in post. maybe else.
my objective not chunlinhan library work (but thank great work), rm04 send email on wifi via trigger event on arduino card. don't care route take.
ideally want work pro-mini happy work in prototype mode on uno or mega.
i have accomplished sending email using ethernet both ethernet shield , enc28j60 ethernet card. using smtp2go resolve internet email blocking problems. not unfamiliar terrain.
it may simplest if send smtp direct rm04 did enc28j60, (which subject , 2 line notice)
an alternative route may use wifi card web-server sends http get/post via url "relay" site contain message. in case have send destination email address content. website email-fowarding process add subject , content.
somehow think if spi work between arduino , rm04 (knew pins numbers) rely on chunlinhan libary , figure out there, don't know if spi part of process have seen posts referencing chunlinhan libary use, 5v, ground, , pins 21 , 22 on rm04 , pin 0 , 1 on arduino.
i got both enc28j60 , regular ethernet shield sending email excellent work done create library jcw/ethercard on github , code @ end of post in case helps else. (some tweaks depending on card, think ethernet library called)
thanks work people have done , suggestions email sent view wifi either straight smtp or via web web relay.
i pieced stuff together, people noted in code examples did heavy lifting. sorry if got inadvertently deleted.
getting rm04 send email on wifi on trigger event arduino card.
i person can't seem rm04 respond in way examples in chunlinhan/wifirm04 library. i have read every post on forum concerning , many others. got stopped @ "serial1" error.
i have used code below rayshobby.net (thanks ray). , have been able talk rm04 , in post. maybe else.
code: [select]
void setup() {
serial.begin(57600);
}
void loop() {
boolean has_request = false;
if (serial.available()) {
while(serial.available()) {char c = serial.read();}
has_request = true;
}
if (has_request) {
serial.println("http/1.1 200 ok");
serial.println("content-type: text/html");
serial.println("connection: close"); // connection closed after completion of response
serial.println("refresh: 5"); // refresh page automatically every 5 sec
string sr = "<!doctype html>\n";
sr += "<html<\n";
// output value of each analog input pin
for (int analogchannel = 0; analogchannel < 6; analogchannel++) {
int sensorreading = analogread(analogchannel);
sr += "analog input ";
sr += analogchannel;
sr += " ";
sr += sensorreading;
sr += "<br />\n";
}
sr += "</html>";
serial.print("content-length: ");
serial.print(sr.length());
serial.print("\r\n\r\n");
serial.print(sr);
has_request = false;
}
}
my objective not chunlinhan library work (but thank great work), rm04 send email on wifi via trigger event on arduino card. don't care route take.
ideally want work pro-mini happy work in prototype mode on uno or mega.
i have accomplished sending email using ethernet both ethernet shield , enc28j60 ethernet card. using smtp2go resolve internet email blocking problems. not unfamiliar terrain.
it may simplest if send smtp direct rm04 did enc28j60, (which subject , 2 line notice)
an alternative route may use wifi card web-server sends http get/post via url "relay" site contain message. in case have send destination email address content. website email-fowarding process add subject , content.
somehow think if spi work between arduino , rm04 (knew pins numbers) rely on chunlinhan libary , figure out there, don't know if spi part of process have seen posts referencing chunlinhan libary use, 5v, ground, , pins 21 , 22 on rm04 , pin 0 , 1 on arduino.
i got both enc28j60 , regular ethernet shield sending email excellent work done create library jcw/ethercard on github , code @ end of post in case helps else. (some tweaks depending on card, think ethernet library called)
thanks work people have done , suggestions email sent view wifi either straight smtp or via web web relay.
code: [select]
/*
adapted advanced chat server dw sending email
uipethernet enc28j60
remember pins 10 11 12 13 was
circuit:
* ethernet shield attached pins 10, 11, 12, 13
*5v grnd
created 18 dec 2009
by david a. mellis
modified 9 apr 2012
by tom igoe
redesigned make use of operator== 25 nov 2013
by norbert truchsess
changes (removed) application stuff email & motor & photo don winchell jan 2015
*/
#include <uipethernet.h>
#include <spi.h>
#include <servo.h>
///////////////////////
ethernetclient client;
char server[] = "smtpcorp.com"; // smtp2go info , use correct info
byte mac[] = {
0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
//ipaddress ip(192,168,0,100); // leave out dhcp
////////////////////////////
void setup() {
// open serial communications , wait port open:
serial.begin(9600);
// while (!serial) {
// wait serial port connect. needed leonardo only
// }
serial.println(" start ");
// ethernet.begin(mac, ip, gateway, gateway, subnet);
delay(2000);
serial.println(f("ready. press 'e' send."));
}
void loop() {
byte inchar;
inchar = serial.read();
if(inchar == 'e')
{
serial.println("run sendemailfunction() ");
sendemailfunction(); // email sending function.
}
} // end of main loop()
///////////////////////////////functions ///////////////////
void sendemailfunction() {
//ethernet.begin(mac, ip); // took out dhcp, see below
// start listening clients
ethernet.begin(mac);
serial.print("server address:");
serial.println(ethernet.localip());
delay(100);
byte inchar;
// inchar = serial.read();
inchar = 'e';
if(inchar == 'e')
{
if(sendemail()) serial.println(f(" email sent"));
else serial.println(f("email failed"));
}
}
byte sendemail()
{
byte thisbyte = 0;
byte respcode;
if(client.connect(server,2525)) { // 2525 recommended port smtp2go 25
serial.println(f(" connected server on port 2525"));
}
else {
serial.println(f(" connection failed"));
return 0;
}
if(!ercv()) return 0;
serial.println(f("sending helo"));
// change public ip
client.println(f("ehlo xxx.com"));
if(!ercv()) return 0;
client.println(f("auth login "));
delay(100);
if(!ercv()) return 0;
client.println(f("zg9----------------------------29t")); // 64 bit uname
delay(100);
if(!ercv()) return 0;
client.println(f("o--------------------------28=")); // 64 bit pw
// if(!ercv()) return 0;
// client.println(f(""));
if(!ercv()) return 0;
serial.println(f(" sending from"));
// change email address (sender)
client.println(f("mail from:<tr@xxx.com>"));
if(!ercv()) return 0;
// change recipient address
serial.println(f("sending to"));
client.println(f("rcpt to:<ell@xxx.com>"));
// client.println(f("rcpt to:<support@xxxt.com>"));
if(!ercv()) return 0;
serial.println(f("sending data"));
client.println(f("data"));
if(!ercv()) return 0;
serial.println(f(" >>> sending email"));
// change recipient address
client.println(f("to: <ll@xxxt.com>"));
// change address
client.println(f("from: xxxxxxx <xxx@xxxt.com>"));
client.println(f(" subject: content here \r\n"));
// client.println(f(" content here better take look. "));
// client.println(f("your content here e" ));
// client.println(f("your content here "));
client.println(f("."));
if(!ercv()) return 0;
serial.println(f(" sending quit"));
client.println(f("quit"));
if(!ercv()) return 0;
client.stop();
serial.println(f("disconnected"));
return 1;
}
byte ercv()
{
byte respcode;
byte thisbyte;
int loopcount = 0;
while(!client.available()) {
delay(1);
loopcount++;
// if nothing received 10 seconds, timeout
if(loopcount > 10000) {
client.stop();
serial.println(f("\r\ntimeout"));
return 0;
}
}
respcode = client.peek();
while(client.available())
{
thisbyte = client.read();
serial.write(thisbyte);
}
if(respcode >= '4')
{
efail();
return 0;
}
return 1;
}
void efail()
{
byte thisbyte = 0;
int loopcount = 0;
client.println(f("quit"));
while(!client.available()) {
delay(1);
loopcount++;
// if nothing received 10 seconds, timeout
if(loopcount > 10000) {
client.stop();
serial.println(f("\r\ntimeout"));
return;
}
}
while(client.available())
{
thisbyte = client.read();
serial.write(thisbyte);
}
client.stop();
serial.println(f("disconnected"));
serial.end(); // turn off serial print after email process completes.
}
i pieced stuff together, people noted in code examples did heavy lifting. sorry if got inadvertently deleted.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > connect HLK-RM04 to arduino uno (or mega)
arduino
Comments
Post a Comment