Comments (3)
I found the solution:
Convert data in loop{} not before sending packet.
global declaration:
char dataChar[51];
///////////////////////////////////////////////////////////////////////////////////////////////////////
void loop () {
ethPaket = ether.packetLoop(ether.packetReceive());
if(ethPaket) prijemPaketu();
wdt_reset();
if (millis() > timer + 5000)
{
timer = millis();
power=random(1, 5000);
t=random(-50, 50);
dataString = ArduinoID + "&t1=" + t + "&power=" + power + "\r\n";
dataString.toCharArray(dataChar, 50);
odeslaniPaketu(dataChar);
}
}//end loop
//////////////////////////////////////////////////
void odeslaniPaketu(char dataChar[]){
ether.browseUrl(PSTR("/shome/arduino/elektromer.php?"), dataChar, server, callback);
}
from minicore.
Can you isolate the problem please (smallest code possible while still being able to demonstrate the problem), and then upload the code so I'm able to test it myself?
from minicore.
Here's the code:
/*
* Test program
* seding data to server 192,168,0,104
*/
#include <EtherCard.h>
#include <avr/wdt.h>
/********************************************************************/
#define DEBUG (true)
String ArduinoID= "ID=03";
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x33,0x43 };
static byte myip[] = { 192,168,0,36 };
static byte gwip[] = { 192,168,0,1 };
static byte server[] = { 192,168,0,104 };
byte Ethernet::buffer[400]; // tcp ip send and receive buffer
int t,power;
unsigned long timer = millis();
uint16_t ethPaket;
String dataString;
const char pageOk[] PROGMEM ="HTTP/1.0 200 OK\r\n Content-Type: text/html\r\n\r\nOK";
/////////////////////////////////////////////////////////////////// called when the client request is complete
static void callback (byte status, word off, word len) {
Ethernet::buffer[off+300] = 0;
if DEBUG Serial.println((const char*) Ethernet::buffer + off);
}
////////////////////////////////////////////////////////////////////////////////////////
void setup () {
if DEBUG Serial.begin(115200);
if DEBUG Serial.println(F("Start - DEBUG ON"));
wdt_enable(WDTO_4S);
init_ethernet();
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
void loop () {
ethPaket = ether.packetLoop(ether.packetReceive());
if(ethPaket) prijemPaketu();//dotaz na http
wdt_reset();
if (millis() > timer + 5000)
{
timer = millis();
power=random(1, 5000);
t=random(-50, 50);
dataString = ArduinoID + "&t1=" + t + "&power=" + power + "\r\n";
odeslaniPaketu(dataString);
}
}//end loop
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////
void odeslaniPaketu(String dataString){
char dataChar[dataString.length()+1];
dataString.toCharArray(dataChar, dataString.length());
if DEBUG Serial.println(dataChar);
if DEBUG Serial.print(F("<<< REQ "));
ether.browseUrl(PSTR("/shome/arduino/elektromer.php?"), dataChar, server, callback);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
void prijemPaketu(){
if DEBUG Serial.println(F("<<<------------->>>"));
char* data = (char *) Ethernet::buffer + ethPaket;
if DEBUG Serial.println(data);
memcpy_P(ether.tcpOffset(), pageOk, sizeof pageOk);
ether.httpServerReply(sizeof pageOk - 1);
}
////////////////////////////////////////////////////////////////////////////////////////////////
void init_ethernet(void){
if (ether.begin(sizeof Ethernet::buffer, mymac,10)== 0)
if DEBUG Serial.println(F("Failed Ethernet controller"));
if (!ether.dhcpSetup()){
ether.staticSetup(myip, gwip);
if DEBUG Serial.println(F("No DHCP, Static IP!"));
}
ether.copyIp(ether.hisip, server);
if DEBUG{
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
ether.printIp("DHCP: ", ether.dhcpip); // output IP address of the DHCP server
ether.printIp("SRV: ", ether.hisip);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
from minicore.
Related Issues (20)
- ATmega328PB-AU - signature mismatch HOT 5
- uP_table does not know mcuid 1753 HOT 6
- Upload error: cannot set com-state on COM port and unable to open programmer error HOT 13
- Ch340 upload problem HOT 2
- Problems with atmega 328pb and minicore? HOT 1
- atmega328pb wrong fuse settings? HOT 39
- No separate SPDR0 SPDR1 for the ATMega328PB? HOT 2
- avrdude urclock_res_check() error: HOT 9
- Clock options for ATMega328P are ambiguous HOT 1
- Not able to burn bootloader to Atmega88PB HOT 6
- MCUSR always reports 0 at startup HOT 13
- [feature] New 9.216MHz to Supported clock frequency.
- Optiboot backward compatibility HOT 6
- Syntax Error HOT 11
- Trying to enlarge pinout diagrams in README fails with 'Non-Image content-type returned' HOT 2
- MiniCore Burn Bootloader - Not Working on M3 MacBook Pro HOT 5
- Warnings with TimerInterrupt library
- is LGT8F328P supported ? HOT 1
- Fails to compile Strings declared empty on Atmega328PB HOT 3
- Internal Pull up error mega328 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minicore.