Code from post#1
#include <WiFi.h>
/*
SerialPassthrough sketch
Some boards, like the Arduino 101, the MKR1000, Zero, or the Micro, have one
hardware serial port attached to Digital pins 0-1, and a separate USB serial
port attached to the IDE Serial Monitor. This means that the "serial
passthrough" which is possible with the Arduino UNO (commonly used to interact
with devices/shields that require configuration via serial AT commands) will
not work by default.
This sketch allows you to emulate the serial passthrough behaviour. Any text
you type in the IDE Serial monitor will be written out to the serial port on
Digital pins 0 and 1, and vice-versa.
On the 101, MKR1000, Zero, and Micro, "Serial" refers to the USB Serial port
attached to the Serial Monitor, and "Serial1" refers to the hardware serial
port attached to pins 0 and 1. This sketch will emulate Serial passthrough
using those two Serial ports on the boards mentioned above, but you can change
these names to connect any two serial ports on a board that has multiple ports.
created 23 May 2016
by Erik Nyquist
*/
uint8_t stopFrame[] { 0x56, 0x00, 0x36, 0x01, 0x00};
uint8_t startFrame[] { 0x56, 0x00, 0x36, 0x01, 0x02};
uint8_t lengthbuffer[] {0x56, 0x00, 0x34, 0x01, 0x00};
uint8_t startMotion[] {0x56, 0x00, 0x37, 0x01, 0x01};
uint8_t MotionStatus[] { 0x56, 0x00, 0x38, 0x00};
uint8_t readBuffer[] {0x56, 0x00, 0x32, 0x0C, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
uint8_t Motionparam1[] {0x56, 0x00, 0x43, 0x01, 0x01};
uint8_t Motionparam2[] {0x56, 0x00, 0x43, 0x01, 0x02};
uint8_t Motionparam3[] {0x56, 0x00, 0x43, 0x01, 0x03};
uint8_t Motionparam4[] {0x56, 0x00, 0x43, 0x01, 0x04};
uint8_t SetMParam1[] {0x56, 0x00, 0x42, 0x03, 0x00, 0x01, 0x01};
uint8_t reponse[1000];
int phdelay = 30;
WiFiClient client;
void printVector(uint8_t *vector, unsigned int nubmer)
{
for(unsigned int i = 0; i< nubmer;++i)
{
Serial.print(" ");
Serial.print(vector[i], HEX);
}
Serial.println();
}
void setup()
{
Serial.begin(115200);
Serial2.begin(115200);//, SERIAL_8N1, 16, 17);
WiFi.begin("Freebox-599EFF","key");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
pinMode(2, OUTPUT);
delay(1000);
Serial2.write(SetMParam1, 7); Serial2.flush();
int ib = Serial2.readBytes(reponse, 10);
printVector(reponse, ib);
}
void loop()
{
int i = 0;
char querystring[200];
while(true)
{
Serial.println("Start");
Serial2.write(startFrame, 5);
Serial2.flush();
Serial2.readBytes(reponse, 5);
Serial2.write(stopFrame, 5);
Serial2.flush();
Serial2.readBytes(reponse, 5);
Serial2.write(lengthbuffer, 5);
Serial2.flush();
Serial2.readBytes(reponse, 9);
int iL = 0;
iL = reponse[5];
iL = iL << 8;
iL += reponse[6];
iL = iL << 8;
iL += reponse[7];
iL = iL << 8;
iL += reponse[8];
Serial.print("Size : ");
Serial.println(iL);
if(client.connect("192.168.1.16", 80))
{
client.println("POST /newpic.php HTTP/1.1");
client.println("Host: 192.168.1.16");
client.println("Content-Type: multipart/form-data; boundary=---------------------------139955009910887227731308057551");
sprintf(querystring, "Content-Length: %d", 230 + iL);
client.println(querystring);
client.println();
client.println("-----------------------------139955009910887227731308057551");
client.println("Content-Disposition: form-data; name=\"file\"; filename=\"datapic.jpg\"");
client.println("Content-Type: application/x-php");
client.println();
int addr = 0;
int sizeR = iL;
readBuffer[6] = (addr >> 24) & 0xFF;
readBuffer[7] = (addr >> 16) & 0xFF;
readBuffer[8] = (addr >> 8) & 0xFF;
readBuffer[9] = (addr & 0xFF);
readBuffer[10] = (sizeR >> 24) & 0xFF;
readBuffer[11] = (sizeR >> 16) & 0xFF;
readBuffer[12] = (sizeR >> 8) & 0xFF;
readBuffer[13] = (sizeR & 0xFF);
Serial2.write(readBuffer, 16);
Serial2.flush();
Serial2.readBytes(reponse, 5);
int u = 1000;
while(sizeR != 0)
{
u = min(1000, sizeR);
Serial2.readBytes(reponse, u);
client.write(reponse, u);
sizeR = sizeR - u;
}
client.println();
client.println("-----------------------------139955009910887227731308057551--");
client.println();
while (client.available() == 0);
String line;
while(client.available())
{
line = client.readStringUntil('\r');
}
// phdelay = line.toInt();
}
delay(500);
Serial2.write(startFrame, 5);
Serial2.flush();
Serial2.readBytes(reponse, 5);
}
}
When the program stops does it stop at executing the same code?